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'))

