localGPT icon indicating copy to clipboard operation
localGPT copied to clipboard

Docker connection issue between rag-api container and local Ollama service

Open KyRosDz9 opened this issue 5 months ago • 6 comments

I am encountering a persistent error in the logs of the rag-api container. Although the initialization seems correct at first — models are loaded and the endpoints respond with 200 — the application repeatedly throws the following error: ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError(... Failed to establish a new connection: [Errno 111] Connection refused))

This indicates that the rag-api service is trying to contact Ollama at 172.18.0.1:11434 (likely the Docker gateway to the host), but the connection is consistently refused. However, GET requests to /models return a 200 status code, suggesting that the local Ollama API is functional from the host, but inaccessible from within the container.

Technical context: I am running on Windows with Ollama already installed locally. I have not restarted ollama serve because it returns the following error: Error: listen tcp 127.0.0.1:11434: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.

This makes sense since the Ollama service is already running.

I have not reinstalled Ollama via curl because it was already present on my machine.

The rag-api container tries to reach Ollama via the address 172.18.0.1:11434, but Ollama is only listening on 127.0.0.1 (the loopback interface). The host’s loopback interface (127.0.0.1) is not accessible from a Docker container, even when attempting to route through the Docker gateway (172.18.0.1).

Error :

Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190558590>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190369110>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190549490>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919036b2d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190db7410>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190548050>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054c2d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91d8bfc1d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190558090>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054b950>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190369090>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054ecd0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919055ba90>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91905489d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91905238d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054e3d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91905228d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f91905493d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9190558e50>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054c6d0>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919036c090>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054aa10>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054ba90>: Failed to establish a new connection: [Errno 111] Connection refused')) rag-api | ⚠️ Could not get Ollama models: HTTPConnectionPool(host='172.18.0.1', port=11434): Max retries exceeded with url: /api/tags (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f919054cc90>: Failed to establish a new connection: [Errno 111] Connection refused'))

Image

Image

KyRosDz9 avatar Jul 16 '25 10:07 KyRosDz9

When you try to access Ollama from another machine in the network, you need to set the variable OLLAMA_HOST on the machine with 0.0.0.0 (otherwise Ollama will refuse to respond), have you already done it ? Maybe it is the problem here (check OLLAMA_HOST on Google, lots of pages talk about the problem)

AutreMachine avatar Jul 16 '25 12:07 AutreMachine

Thanks for the suggestion! I did try setting OLLAMA_HOST=0.0.0.0, but unfortunately it didn’t solve the issue. Ollama still refuses the connection from other machines on the network. I double-checked the environment variable and even restarted the service, but no luck. Let me know if you have any other ideas!

KyRosDz9 avatar Jul 16 '25 18:07 KyRosDz9

I solved this by asking chatgpt. For context i'm on windows and run it via a simple $docker-compose up -d. When I didn't get any models when ollama was clearly running I asked something allong the lines "fix the docker-compose.yml to get the ollama on the host machine" and pasted the file. I you want I can send you my new version of the docker-compose.yml.

BR-Amp avatar Jul 22 '25 19:07 BR-Amp

@BR-Amp can you add that here. It might be helpful for others.

PromtEngineer avatar Jul 23 '25 06:07 PromtEngineer

docker-compose.txt

BR-Amp avatar Jul 23 '25 06:07 BR-Amp

@KyRosDz9 have you succeeded ? I was thinking that maybe you had a firewall blocking the port 11434 between your machines ?

AutreMachine avatar Jul 23 '25 16:07 AutreMachine