Open WebUI or another Docker app cannot connect to Ollama
[Errno 111] Connection refusedShort answer
Inside a container, localhost is the container itself, not your machine, so a call to 127.0.0.1:11434 never reaches Ollama. Point the app at host.docker.internal, or run it on the host network. Also make Ollama listen beyond loopback with OLLAMA_HOST, and clear a bad URL that Open WebUI saved earlier.
Fix it fast
1Find out which cause you have
Read which address the app tried. If the log shows 127.0.0.1, the app is calling its own container.
docker logs open-webui --tail 502Match what you see, then jump to its fix
What does the error look like?
[Errno 111] Connection refusedConnect call failed ('127.0.0.1', 11434)Connection error: Cannot connect to host
Cause 1 of 3
localhost inside the container is the container
1Check
Open WebUI's docs state that localhost means the machine or container running Open WebUI. Look at the URL the container was started with.
docker inspect open-webui --format '{{range .Config.Env}}{{println .}}{{end}}' | grep OLLAMA2Fix
Start the container with the host alias and OLLAMA_BASE_URL set to it, or use the host network.
docker run -d -p 3000:8080 \
-e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data --name open-webui --restart always \
ghcr.io/open-webui/open-webui:main
# or, on the host network (the UI is then on port 8080)
docker run -d --network=host -v open-webui:/app/backend/data \
-e OLLAMA_BASE_URL=http://127.0.0.1:11434 \
--name open-webui --restart always ghcr.io/open-webui/open-webui:main3Verify
Reload the UI and open the model list, or read the container log again.
docker logs open-webui --tail 20Confirmed by docs.openwebui.com
Cause 2 of 3
Ollama only listens on 127.0.0.1
1Check
By default Ollama binds 127.0.0.1 port 11434. A container reaching the host through the Docker bridge arrives on another interface.
ss -ltn | grep 114342Fix
Set OLLAMA_HOST on the Ollama service and restart it. On Linux with systemd, add the variable through an override.
sudo systemctl edit ollama
# in the editor add:
# [Service]
# Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl daemon-reload
sudo systemctl restart ollama3Verify
The listener now shows 0.0.0.0 or *, and the app connects.
ss -ltn | grep 11434Confirmed by docs.ollama.com
Cause 3 of 3
Open WebUI kept an old URL in its database
1Check
Open WebUI stores settings it has saved, and a saved value takes precedence over the environment variable.
docker inspect open-webui --format '{{range .Config.Env}}{{println .}}{{end}}' | grep -E 'OLLAMA|PERSISTENT|RESET'2Fix
Start once with RESET_CONFIG_ON_START=true to reapply the environment values, or set ENABLE_PERSISTENT_CONFIG=false so the environment always wins. Remove the reset flag again afterwards.
docker rm -f open-webui
docker run -d -p 3000:8080 -e RESET_CONFIG_ON_START=true \
-e OLLAMA_BASE_URL=http://host.docker.internal:11434 \
--add-host=host.docker.internal:host-gateway \
-v open-webui:/app/backend/data --name open-webui \
ghcr.io/open-webui/open-webui:main3Verify
The Ollama connection in the admin settings shows the new URL.
docker logs open-webui --tail 20Confirmed by docs.openwebui.com
How do I stop it coming back?
- Never put localhost in a container's environment when the target runs on the host.
- Keep the full docker run or compose file in version control so the URL has one source of truth.
- Test the path with the same address the app uses, from inside the app's container.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
AI
The shell says ollama: command not found
command not found: ollama
The shell can only run ollama if the binary is installed in the same place the shell runs.
2 causes, each with a fixAI
Ollama is slow and the GPU is not being used
Replies arrive a few tokens per second on a machine with a GPU
Run ollama ps and read the PROCESSOR column: 100% GPU means the model is on the card, anything with CPU means it is not fully there.
4 causes, each with a fixAI
ollama Python library fails with httpx.ConnectError
httpx.ConnectError
httpx.ConnectError means the client could not open a connection to the address it used.
3 causes, each with a fixAI
Chroma data is empty after a restart in LangChain
The collection is empty after the app restarts
Chroma only keeps data when you ask it to.
3 causes, each with a fixAI
TextLoader fails on a text file with an encoding error
UnicodeDecodeError: codec can't decode byte
TextLoader opens the file with the encoding you give it, or the system default if you give none.
3 causes, each with a fixAI
LlamaIndex cannot import Ollama from llama_index.llms
ImportError: cannot import name 'Ollama' from 'llama_index.llms' (unknown location)
Since LlamaIndex 0.10, each integration is its own package and the old top-level llama_index.llms path is gone.
3 causes, each with a fix