Fix Ollama 127.0.0.1:11434 connect: connection refused
Ollama connection refused on 11434: no server, a server on another address or port, or localhost called inside a container. Match the address and OLLAMA_HOST.
Error: Post "http://127.0.0.1:11434/api/show": dial tcp 127.0.0.1:11434: connect: connection refusedNothing is listening at the address and port you called. Either the Ollama server isn't running, it's listening on a different address or port, or a container called localhost and reached itself. Match the server's Listening on log line with the address the client uses (OLLAMA_HOST). The message above is Ollama 0.5.7 output from official repository issue #8773; each client words the same failure differently.
| Client | Message with no server running (tested) |
|---|---|
ollama CLI 0.40.11 | Error: could not connect to ollama server, run 'ollama serve' to start it |
| curl 8.17.0 | curl: (7) Failed to connect to 127.0.0.1 port 11434 after 0 ms: Could not connect to server |
Python ollama 0.6.3 | ConnectionError: Failed to connect to Ollama. Please check that Ollama is downloaded, running and accessible. |
Python urllib | urllib.error.URLError: <urlopen error [Errno 111] Connection refused> |
[1] Check whether the server is up. Any response means it is alive.
$ curl http://127.0.0.1:11434/api/versionIf it can't connect, check the way you run it. On a Linux install, systemctl status ollama, and logs with journalctl -u ollama --no-pager --follow --pager-end (official docs). On macOS, ~/.ollama/logs/server.log; in Docker, docker logs <container name>. If you run it without a service, start ollama serve in another terminal.
[2] Find where the server listens. It logs one line at startup. Below are the official image (default OLLAMA_HOST=0.0.0.0:11434) and the same image with -e OLLAMA_HOST=127.0.0.1:11434:
$ docker logs ollama 2>&1 | grep -o 'msg="Listening on [^"]*"'msg="Listening on [::]:11434 (version 0.40.11)"msg="Listening on 127.0.0.1:11434 (version 0.40.11)"127.0.0.1 accepts connections only from inside that machine (or that container). Per the official FAQ, 127.0.0.1:11434 is also the default for a regular install. Calling the loopback-bound container from another container was refused:
curl: (7) Failed to connect to 192.0.2.10 port 11434 after 0 ms: Could not connect to server[3] If you changed the port, give the client the same value. The ollama CLI reads OLLAMA_HOST to find the server too. With the server container (ollama) started with -e OLLAMA_HOST=0.0.0.0:11435, here is its CLI with the variable cleared and then set:
$ docker exec -e OLLAMA_HOST= ollama ollama listError: could not connect to ollama server, run 'ollama serve' to start it$ docker exec -e OLLAMA_HOST=127.0.0.1:11435 ollama ollama listNAME ID SIZE MODIFIEDqwen2.5:0.5b-instruct-fp16 c82efd44bfdc 994 MB 8 minutes agoqwen2.5:0.5b a8b0c5157701 397 MB 9 minutes agoThe reverse also happens: a leftover OLLAMA_HOST in your shell points at an old port. Check with echo $OLLAMA_HOST. Apps such as Open WebUI use their own configured address, so check that setting.
[4] From inside a container, don't use localhost. A container's localhost is the container itself. With Ollama listening on 0.0.0.0 in another container, curl in the client container couldn't reach it via localhost, and got an answer right away via the Ollama container's address:
$ curl -sS http://localhost:11434/api/version; echo "exit=$?"curl: (7) Failed to connect to localhost port 11434 after 0 ms: Could not connect to serverexit=7$ curl -sS http://192.0.2.10:11434/api/version; echo; echo "exit=$?"{"version":"0.40.11"}exit=0Which address to call:
| Ollama runs in | Client runs in | Call |
|---|---|---|
| Same container or machine | Same place | http://127.0.0.1:11434 |
| Container A | Container B on the same Compose or user-defined network | http://<service or container name of A>:11434 |
| Host (regular install) | A container | Add --add-host host.docker.internal:host-gateway, call http://host.docker.internal:11434 |
Docker's docs say containers on user-defined networks resolve each other by name, while the default bridge allows IP only. In the last row, per Docker's host-gateway docs, the container arrives on the host's internal IP. If the host's Ollama listens only on the default 127.0.0.1, it refuses that connection for the same reason as in [2]. Opening the server on 0.0.0.0 exposes an unauthenticated API to every device on the network; how to narrow it with a firewall is covered in calling Ollama from another device.
[5] If it starts and then stops, read the end of the log. If the folder set in OLLAMA_MODELS is not writable, the server exits right after starting with mkdir … permission denied — see step [5] of Change Ollama model storage location. When it's not the server but the runner loading the model that dies for lack of memory, see model requires more system memory.