Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
AI and LLM integration

Open WebUI or another Docker app cannot connect to Ollama

Error[Errno 111] Connection refused

Short 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.

  • Applies to Open WebUI main image, Ollama 0.x, Docker 27, Ubuntu 24.04
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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 50
  2. 2Match what you see, then jump to its fix

    1. 1Connect call failed ('127.0.0.1', 11434) from the app containerlocalhost inside the container is the containerFix
    2. 2The URL is right but the connection is still refusedOllama only listens on 127.0.0.1Fix
    3. 3You changed OLLAMA_BASE_URL and nothing changedOpen WebUI kept an old URL in its databaseFix

What does the error look like?

  • [Errno 111] Connection refused
  • Connect 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 OLLAMA

2Fix

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:main

3Verify

Reload the UI and open the model list, or read the container log again.

docker logs open-webui --tail 20

Confirmed by docs.openwebui.com

Did this fix it?

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 11434

2Fix

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 ollama

3Verify

The listener now shows 0.0.0.0 or *, and the app connects.

ss -ltn | grep 11434

Confirmed by docs.ollama.com

Did this fix it?

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:main

3Verify

The Ollama connection in the admin settings shows the new URL.

docker logs open-webui --tail 20

Confirmed by docs.openwebui.com

Did this fix it?

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

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 fix

AI

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

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.