[GH-ISSUE #3200] ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7851288df1c0>: Failed to establish a new con… #1974

Closed
opened 2026-04-12 12:09:09 -05:00 by GiteaMirror · 18 comments
Owner

Originally created by @jyotiyadav94 on GitHub (Mar 17, 2024).
Original GitHub issue: https://github.com/ollama/ollama/issues/3200

What is the issue?

ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7851288df1c0>: Failed to establish a new connection: [Errno 111] Connection refused'))

What did you expect to see?

I am running the below code in google collab

`!pip3 install llama-index==0.8.59
!pip3 install openai==0.28.1
!pip3 install pypdf==3.17.2

from llama_index.llms import Ollama
llm = Ollama(model="gemma")

resp = llm.complete("What did Rome grow? Be concise.")
print(resp)

`

Steps to reproduce

I am running the below code in google collab
resp = llm.complete("What did Rome grow? Be concise.") print(resp)

I am receiving at this step

Are there any recent changes that introduced the issue?

No response

OS

No response

Architecture

No response

Platform

No response

Ollama version

No response

GPU

No response

GPU info

No response

CPU

No response

Other software

No response

Originally created by @jyotiyadav94 on GitHub (Mar 17, 2024). Original GitHub issue: https://github.com/ollama/ollama/issues/3200 ### What is the issue? ConnectionError: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate/ (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7851288df1c0>: Failed to establish a new connection: [Errno 111] Connection refused')) ### What did you expect to see? I am running the below code in google collab `!pip3 install llama-index==0.8.59 !pip3 install openai==0.28.1 !pip3 install pypdf==3.17.2 from llama_index.llms import Ollama llm = Ollama(model="gemma") resp = llm.complete("What did Rome grow? Be concise.") print(resp) ` ### Steps to reproduce I am running the below code in google collab `resp = llm.complete("What did Rome grow? Be concise.") print(resp)` I am receiving at this step ### Are there any recent changes that introduced the issue? _No response_ ### OS _No response_ ### Architecture _No response_ ### Platform _No response_ ### Ollama version _No response_ ### GPU _No response_ ### GPU info _No response_ ### CPU _No response_ ### Other software _No response_
GiteaMirror added the bug label 2026-04-12 12:09:09 -05:00
Author
Owner

@mxyng commented on GitHub (Mar 17, 2024):

Ollama requires a running instance. Calling llm.complete() is not sufficient. See the README.md for setting up Ollama or this example on running Ollama in a Jupyter notebook1 .

<!-- gh-comment-id:2002604355 --> @mxyng commented on GitHub (Mar 17, 2024): Ollama requires a running instance. Calling `llm.complete()` is not sufficient. See the README.md for setting up Ollama or this example on running Ollama in a Jupyter notebook[^1]. [^1]: https://github.com/ollama/ollama/tree/main/examples/jupyter-notebook
Author
Owner

@aryangoyal90 commented on GitHub (Apr 11, 2024):

@mxyng In my case . I am integrating a streamlit application (uses Ollama) in docker.
when I enter the docker command to run the application it is running on local host but when I enter a prompt or ask any question then I got the problem like @jyotiyadav94 described

<!-- gh-comment-id:2049967114 --> @aryangoyal90 commented on GitHub (Apr 11, 2024): @mxyng In my case . I am integrating a streamlit application (uses Ollama) in docker. when I enter the docker command to run the application it is running on local host but when I enter a prompt or ask any question then I got the problem like @jyotiyadav94 described
Author
Owner

@Patdill commented on GitHub (May 8, 2024):

Same issue as @aryangoyal90

<!-- gh-comment-id:2101554505 --> @Patdill commented on GitHub (May 8, 2024): Same issue as @aryangoyal90
Author
Owner

@mxyng commented on GitHub (May 8, 2024):

without knowing exactly how ollama is deployed, all I can say is if ollama is not running in that specific container, localhost address is incorrect

localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. host.docker.internal for docker desktop) or another container

<!-- gh-comment-id:2101604918 --> @mxyng commented on GitHub (May 8, 2024): without knowing exactly how ollama is deployed, all I can say is if ollama is not running in that specific container, `localhost` address is incorrect localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. `host.docker.internal` for docker desktop) or another container
Author
Owner

@lprakashv commented on GitHub (May 9, 2024):

localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. host.docker.internal for docker desktop) or another container

Worked for me using base_url='http://host.docker.internal:11434'

<!-- gh-comment-id:2102334237 --> @lprakashv commented on GitHub (May 9, 2024): > localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. `host.docker.internal` for docker desktop) or another container Worked for me using `base_url='http://host.docker.internal:11434'`
Author
Owner

@Urvesh71 commented on GitHub (Aug 26, 2024):

same issue as @jyotiyadav94

<!-- gh-comment-id:2309575178 --> @Urvesh71 commented on GitHub (Aug 26, 2024): same issue as @jyotiyadav94
Author
Owner

@ntelo007 commented on GitHub (Aug 27, 2024):

This did not work for me. Any advice please?

<!-- gh-comment-id:2313143322 --> @ntelo007 commented on GitHub (Aug 27, 2024): This did not work for me. Any advice please?
Author
Owner

@yashgupta67 commented on GitHub (Aug 30, 2024):

same issue as @jyotiyadav94

<!-- gh-comment-id:2322189248 --> @yashgupta67 commented on GitHub (Aug 30, 2024): same issue as @jyotiyadav94
Author
Owner

@asifhaider commented on GitHub (Sep 16, 2024):

Same problem here as @jyotiyadav94

<!-- gh-comment-id:2352929881 --> @asifhaider commented on GitHub (Sep 16, 2024): Same problem here as @jyotiyadav94
Author
Owner

@chuenfaiy commented on GitHub (Sep 24, 2024):

ollama local deploy, Same problem as @jyotiyadav94
cmd curl http://localhost: 11434 is valid when running in terminal.

<!-- gh-comment-id:2370788757 --> @chuenfaiy commented on GitHub (Sep 24, 2024): ollama local deploy, Same problem as @jyotiyadav94 cmd `curl http://localhost: 11434` is valid when running in terminal.
Author
Owner

@HamzaAI9D commented on GitHub (Oct 19, 2024):

image

Check here I'm trying to run Ollama Image and fastapi app but could not access llama but I verified Ollama is running.
I also verified llama3.2 model is pull successfully but when I hit API endpoint I get the below error:

{ "detail": "Failed to read or summarize PDF: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1c9d095b80>: Failed to establish a new connection: [Errno 111] Connection refused'))" }

here below is the my docker-compose.yml file that I used to build docker image:

`version: '3.8'

services:
app:
build: . # Build the FastAPI app using the Dockerfile in the root directory
ports:
- 8000:8000 # Expose FastAPI on port 8000
volumes:
- ./app:/code/app # Mount the FastAPI app directory
command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload
restart: always
depends_on:
- ollama
networks:
- ollama-docker

ollama:
image: ollama/ollama:latest # Use the latest Ollama image
container_name: ollama
volumes:
- ./ollama/ollama:/root/.ollama # Mount the local Ollama directory containing llama3.2 model
pull_policy: always # Ensure that the image is always pulled if there is a new one
tty: true # Keep the container running in the background
restart: unless-stopped # Restart unless manually stopped
ports:
- 11434:11434 # Expose Ollama on port 7869
environment:
- OLLAMA_KEEP_ALIVE=24h # Keep the model alive for 24 hours
- OLLAMA_BASE_URLS=http://host.docker.internal:11434
networks:
- ollama-docker
deploy:
resources:
reservations:
devices:
- driver: nvidia # Enable GPU access
count: 1
capabilities: [gpu]

networks:
ollama-docker:
external: false`

I'm not able to debug where is the issue

<!-- gh-comment-id:2423789745 --> @HamzaAI9D commented on GitHub (Oct 19, 2024): ![image](https://github.com/user-attachments/assets/808f156c-ee4c-4db8-81cb-ecd2d05937e6) Check here I'm trying to run Ollama Image and fastapi app but could not access llama but I verified Ollama is running. I also verified llama3.2 model is pull successfully but when I hit API endpoint I get the below error: `{ "detail": "Failed to read or summarize PDF: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1c9d095b80>: Failed to establish a new connection: [Errno 111] Connection refused'))" }` here below is the my docker-compose.yml file that I used to build docker image: `version: '3.8' services: app: build: . # Build the FastAPI app using the Dockerfile in the root directory ports: - 8000:8000 # Expose FastAPI on port 8000 volumes: - ./app:/code/app # Mount the FastAPI app directory command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload restart: always depends_on: - ollama networks: - ollama-docker ollama: image: ollama/ollama:latest # Use the latest Ollama image container_name: ollama volumes: - ./ollama/ollama:/root/.ollama # Mount the local Ollama directory containing llama3.2 model pull_policy: always # Ensure that the image is always pulled if there is a new one tty: true # Keep the container running in the background restart: unless-stopped # Restart unless manually stopped ports: - 11434:11434 # Expose Ollama on port 7869 environment: - OLLAMA_KEEP_ALIVE=24h # Keep the model alive for 24 hours - OLLAMA_BASE_URLS=http://host.docker.internal:11434 networks: - ollama-docker deploy: resources: reservations: devices: - driver: nvidia # Enable GPU access count: 1 capabilities: [gpu] networks: ollama-docker: external: false` I'm not able to debug where is the issue
Author
Owner

@ninetyhe-90 commented on GitHub (Feb 11, 2025):

localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. host.docker.internal for docker desktop) or another container

Worked for me using base_url='http://host.docker.internal:11434'

this works for me

<!-- gh-comment-id:2650583679 --> @ninetyhe-90 commented on GitHub (Feb 11, 2025): > > localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. `host.docker.internal` for docker desktop) or another container > > Worked for me using `base_url='http://host.docker.internal:11434'` this works for me
Author
Owner

@mzeeshanarshad commented on GitHub (Feb 27, 2025):

Try increasing the timeout.

<!-- gh-comment-id:2686775850 --> @mzeeshanarshad commented on GitHub (Feb 27, 2025): Try increasing the timeout.
Author
Owner

@yashgupta67 commented on GitHub (Feb 27, 2025):

that doesnt work either

On Thu, 27 Feb 2025 at 09:12, mzeeshanarshad @.***>
wrote:

Try increasing the timeout.


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/A45QIF7PNXLKLOTX4Y5FE2L2R2CRRAVCNFSM6AAAAABE2O2GSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBWG43TKOBVGA
.
You are receiving this because you commented.Message ID:
@.***>
[image: mzeeshanarshad]mzeeshanarshad left a comment
(ollama/ollama#3200)
https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850

Try increasing the timeout.


Reply to this email directly, view it on GitHub
https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/A45QIF7PNXLKLOTX4Y5FE2L2R2CRRAVCNFSM6AAAAABE2O2GSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBWG43TKOBVGA
.
You are receiving this because you commented.Message ID:
@.***>

<!-- gh-comment-id:2686958934 --> @yashgupta67 commented on GitHub (Feb 27, 2025): that doesnt work either On Thu, 27 Feb 2025 at 09:12, mzeeshanarshad ***@***.***> wrote: > Try increasing the timeout. > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/A45QIF7PNXLKLOTX4Y5FE2L2R2CRRAVCNFSM6AAAAABE2O2GSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBWG43TKOBVGA> > . > You are receiving this because you commented.Message ID: > ***@***.***> > [image: mzeeshanarshad]*mzeeshanarshad* left a comment > (ollama/ollama#3200) > <https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850> > > Try increasing the timeout. > > — > Reply to this email directly, view it on GitHub > <https://github.com/ollama/ollama/issues/3200#issuecomment-2686775850>, > or unsubscribe > <https://github.com/notifications/unsubscribe-auth/A45QIF7PNXLKLOTX4Y5FE2L2R2CRRAVCNFSM6AAAAABE2O2GSOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMOBWG43TKOBVGA> > . > You are receiving this because you commented.Message ID: > ***@***.***> >
Author
Owner

@Pancat009 commented on GitHub (Mar 24, 2025):

based on Grok:

pkill ollama
nohup OLLAMA_HOST=0.0.0.0 ollama serve &
ollama run deepseek-r1:7b

<!-- gh-comment-id:2747164061 --> @Pancat009 commented on GitHub (Mar 24, 2025): based on Grok: ``` pkill ollama nohup OLLAMA_HOST=0.0.0.0 ollama serve & ollama run deepseek-r1:7b ```
Author
Owner

@bkrishna2006 commented on GitHub (Apr 5, 2025):

image

Check here I'm trying to run Ollama Image and fastapi app but could not access llama but I verified Ollama is running. I also verified llama3.2 model is pull successfully but when I hit API endpoint I get the below error:

{ "detail": "Failed to read or summarize PDF: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1c9d095b80>: Failed to establish a new connection: [Errno 111] Connection refused'))" }

here below is the my docker-compose.yml file that I used to build docker image:

`version: '3.8'

services: app: build: . # Build the FastAPI app using the Dockerfile in the root directory ports: - 8000:8000 # Expose FastAPI on port 8000 volumes: - ./app:/code/app # Mount the FastAPI app directory command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload restart: always depends_on: - ollama networks: - ollama-docker

ollama: image: ollama/ollama:latest # Use the latest Ollama image container_name: ollama volumes: - ./ollama/ollama:/root/.ollama # Mount the local Ollama directory containing llama3.2 model pull_policy: always # Ensure that the image is always pulled if there is a new one tty: true # Keep the container running in the background restart: unless-stopped # Restart unless manually stopped ports: - 11434:11434 # Expose Ollama on port 7869 environment: - OLLAMA_KEEP_ALIVE=24h # Keep the model alive for 24 hours - OLLAMA_BASE_URLS=http://host.docker.internal:11434 networks: - ollama-docker deploy: resources: reservations: devices: - driver: nvidia # Enable GPU access count: 1 capabilities: [gpu]

networks: ollama-docker: external: false`

I'm not able to debug where is the issue

I am facing a similar issue.. calling the ollama docker container service from another container service, both are tagged to the same docker network, but I still get errors. Tried a few options and the errors are -

# api_url = 'http://0.0.0.0:11434/api/generate'  # getting connectin refused error
# api_url = 'http://0.0.0.0:ollama/api/generate'  # getting error failed to parse
# api_url = 'ollama' + '/api/generate'  # no scheme suppied error.. do you mean https://ollama ?
# api_url = 'http://localhost:11434/api/generate' # [Errno 111] Connection refused'
# api_url = 'http://ollama:11434/api/generate' # [Errno 111] Connection refused'))
# api_url = 'http://ollama/api/generate' # Port 80 [Errno 111] Connection refused'))
#api_url = 'http://host.docker.internal:11434' # Failed to resolve 'host.docker.internal' ([Errno -2] Name or service not known)
<!-- gh-comment-id:2780122325 --> @bkrishna2006 commented on GitHub (Apr 5, 2025): > ![image](https://github.com/user-attachments/assets/808f156c-ee4c-4db8-81cb-ecd2d05937e6) > > Check here I'm trying to run Ollama Image and fastapi app but could not access llama but I verified Ollama is running. I also verified llama3.2 model is pull successfully but when I hit API endpoint I get the below error: > > `{ "detail": "Failed to read or summarize PDF: HTTPConnectionPool(host='localhost', port=11434): Max retries exceeded with url: /api/generate (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f1c9d095b80>: Failed to establish a new connection: [Errno 111] Connection refused'))" }` > > here below is the my docker-compose.yml file that I used to build docker image: > > `version: '3.8' > > services: app: build: . # Build the FastAPI app using the Dockerfile in the root directory ports: - 8000:8000 # Expose FastAPI on port 8000 volumes: - ./app:/code/app # Mount the FastAPI app directory command: uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload restart: always depends_on: - ollama networks: - ollama-docker > > ollama: image: ollama/ollama:latest # Use the latest Ollama image container_name: ollama volumes: - ./ollama/ollama:/root/.ollama # Mount the local Ollama directory containing llama3.2 model pull_policy: always # Ensure that the image is always pulled if there is a new one tty: true # Keep the container running in the background restart: unless-stopped # Restart unless manually stopped ports: - 11434:11434 # Expose Ollama on port 7869 environment: - OLLAMA_KEEP_ALIVE=24h # Keep the model alive for 24 hours - OLLAMA_BASE_URLS=http://host.docker.internal:11434 networks: - ollama-docker deploy: resources: reservations: devices: - driver: nvidia # Enable GPU access count: 1 capabilities: [gpu] > > networks: ollama-docker: external: false` > > I'm not able to debug where is the issue I am facing a similar issue.. calling the ollama docker container service from another container service, both are tagged to the same docker network, but I still get errors. Tried a few options and the errors are - # api_url = 'http://0.0.0.0:11434/api/generate' # getting connectin refused error # api_url = 'http://0.0.0.0:ollama/api/generate' # getting error failed to parse # api_url = 'ollama' + '/api/generate' # no scheme suppied error.. do you mean https://ollama ? # api_url = 'http://localhost:11434/api/generate' # [Errno 111] Connection refused' # api_url = 'http://ollama:11434/api/generate' # [Errno 111] Connection refused')) # api_url = 'http://ollama/api/generate' # Port 80 [Errno 111] Connection refused')) #api_url = 'http://host.docker.internal:11434' # Failed to resolve 'host.docker.internal' ([Errno -2] Name or service not known)
Author
Owner

@g0t4 commented on GitHub (Jun 18, 2025):

TRY REBOOTING

I had this issue today and rebooted and it went away... exact same request worked after reboot.

Oddly the error only happened when using httpie's http command, whereas curl worked before the reboot... some sort of connection pooling issue in ollama. But, a restart of ollama didn't fix it. Had to reboot machine

<!-- gh-comment-id:2984450739 --> @g0t4 commented on GitHub (Jun 18, 2025): TRY REBOOTING I had this issue today and `rebooted` and it went away... exact same request worked after reboot. Oddly the error only happened when using httpie's `http` command, whereas `curl` worked before the reboot... some sort of connection pooling issue in ollama. But, a restart of ollama didn't fix it. Had to reboot machine
Author
Owner

@Latimerhtet commented on GitHub (Jul 18, 2025):

localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. host.docker.internal for docker desktop) or another container

Worked for me using base_url='http://host.docker.internal:11434'

This just also worked for me.

<!-- gh-comment-id:3086847850 --> @Latimerhtet commented on GitHub (Jul 18, 2025): > > localhost in docker is not the same localhost since the container exists in a separate network namespace. you either need to address the container host (e.g. `host.docker.internal` for docker desktop) or another container > > Worked for me using `base_url='http://host.docker.internal:11434'` This just also worked for me.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#1974