Ollama connection refused in Docker? Check the caller URL
gist Use a configured Ollama alias on a shared Docker bridge, then check /api/tags from the caller before troubleshooting models.
You stopped about in. Jump back
contents
If a Docker app reports Ollama connection refused, use a reachable Ollama name on a shared network; separate containers have their own loopback addresses (n8n’s connection documentation). If the caller is n8n, use the n8n and Ollama guide to check its credential.
I run Ollama, LiteLLM and n8n as containers on my Unraid box. For this connection check, you need a running Ollama service, access to the caller’s network settings, and curl inside the caller or a test container on the same network.
Step 1: Check the caller’s address
Find the Ollama URL the app actually uses. A value such as http://127.0.0.1:11434 refers to the caller’s container when the request runs there. localhost has the same problem.
From inside that caller, check the loopback address:
curl --silent --show-error --connect-timeout 5 --max-time 10 \
http://127.0.0.1:11434/api/tags
If nothing listens on that container’s loopback port, expect a connection failure. Curl exit code 7 means it could not connect. The accompanying message tells you whether the connection was refused. Exit code 7 alone does not identify the cause. curl error codes
A successful request from the Docker host does not prove that the app container can reach the same address. Test from where the app sends its requests.

curl --silent --show-error --connect-timeout 5 --max-time 10 http://127.0.0.1:11434/api/tags
curl: (7) Failed to connect to 127.0.0.1 port 11434 after 0 ms: Couldn't connect to server
Curl error 7 means the connection failed before any Ollama HTTP response.
Step 2: Reach Ollama through the bridge
For two containers on the same Docker host:
- Attach both to the same user-defined bridge.
- Give Ollama a name or network alias the caller can resolve.
- Save that network attachment in each container’s configuration so recreation keeps it.
- Point the caller at Ollama’s internal port,
11434.
User-defined bridges resolve container names and aliases. Containers on the same bridge can communicate without published host ports. Docker’s default network named bridge does not provide the same automatic name resolution. Docker bridge documentation
Configure ollama.example as an alias on Ollama’s bridge connection.
Repeat the request from the same caller:
curl --silent --show-error --connect-timeout 5 --max-time 10 \
http://ollama.example:11434/api/tags
For an Ollama instance with no installed models, the expected successful response is:
{"models":[]}
GET /api/tags lists installed models. An empty array means the API is reachable and its model list is empty. Ollama list-models documentation
For an app’s native Ollama integration that asks for a base URL, use http://ollama.example:11434. Keep /api/tags on the diagnostic request rather than adding it to that base URL. n8n’s Ollama connection settings

Step 3: Check the listener if the address still fails
Check which address the Ollama server listens on. Ollama’s documented default is 127.0.0.1:11434, which accepts connections within its own network namespace. The server’s OLLAMA_HOST environment variable changes that bind address. Ollama network configuration
The official Docker image is already configured to listen on all container interfaces. A custom image or changed environment may need a different setting. n8n’s Docker instructions
For a service that only listens on loopback, this setting makes it listen on all IPv4 interfaces in its network namespace:
OLLAMA_HOST=0.0.0.0:11434
Set the variable in the environment used to start the Ollama server. Follow the instructions for your installation to apply it: the FAQ describes restarting the macOS app, reloading and restarting the Linux systemd service, or quitting and reopening the Windows app. Ollama environment configuration
0.0.0.0 is a listener setting. The caller connects to a reachable name or address, such as ollama.example.
Ollama’s local API requires no authentication. Keep access limited to trusted callers. Protect a remotely exposed endpoint with authentication and network access controls. Ollama authentication documentation
Step 4: Match the error to the next check
| Result | Meaning | Next check |
|---|---|---|
| Connection refused | The connection was actively rejected, often because no service listens there. | Caller address, port, listener and service status. |
Could not resolve host, curl 6 |
The name did not resolve. | Shared network membership and configured alias. |
Timeout, curl 28 |
The operation exceeded its time limit. | Routing, firewall rules and server response. |
HTTP 4xx or 5xx |
An HTTP server answered. | Request path, proxy settings and response body. |
HTTP 200 with models: [] |
Ollama answered with an empty model list. | Install a model on that instance before selecting it in the app. |
Curl normally treats HTTP error responses as completed transfers. To display headers and the response body while returning exit code 22 for HTTP 400 or higher, use:
curl --silent --show-error --include --fail-with-body \
--connect-timeout 5 --max-time 10 \
http://ollama.example:11434/api/tags
These distinctions follow curl’s error definitions and HTTP failure options.
If curl works but the app still fails, check the app’s saved URL. Confirm it uses the same endpoint as the successful request.
Choose the connection that fits your setup
| Option | Best fit | Tradeoff |
|---|---|---|
| Shared Docker bridge | Caller and Ollama are containers on one host. | Simple name resolution and no host port publishing; both need the same network. |
| Reachable host endpoint | Ollama runs directly on the Docker host. | Requires a host address reachable from the caller, a suitable listener and firewall rules. |
| Separate inference machine | Ollama runs on another computer. | Separates compute resources, but adds network routing and access controls. |
A bridge belongs to one Docker host. Its aliases do not automatically work from another machine. Docker bridge documentation
Common questions
Why does Ollama work on the host but fail in Docker?
The host and container have different loopback addresses. Use an Ollama alias on a shared bridge, or a host endpoint reachable from the container. n8n’s connection troubleshooting
Do I need to publish port 11434?
For containers on the same user-defined bridge, no. They use Ollama’s internal port. Reaching containerized Ollama from the host or another machine may require a published port, depending on the network mode and route. Docker bridge documentation
Will switching to 127.0.0.1 fix connection refused?
Only if Ollama listens inside that same network namespace. It can help when the client chooses IPv6 loopback but Ollama listens only on IPv4. It cannot reach a separate container. n8n’s connection troubleshooting
Does OLLAMA_ORIGINS fix connection refused?
No. It controls allowed browser origins. Fix the address and listener first. Check origin settings when a browser reports a cross-origin error. Ollama FAQ
Why can the app connect but show no models?
Check /api/tags on the same endpoint. An empty list means that instance has no installed models. A populated list gives you the exact model names to check in the app. Ollama list-models documentation
Then check whether the app supports the selected model and the features you need.
Related: local AI guides · all guides.
../local-ai/ every Local AI guide