Quick fix
# One-liner: recreate the container pointing to the host's Ollama + explicit host-gateway on Linux
docker rm -f open-webui
docker run -d --name open-webui --restart always -p 3000:8080 \
--add-host host.docker.internal:host-gateway \
-e OLLAMA_BASE_URLS=http://host.docker.internal:11434 \
-v open-webui:/app/backend/data \
ghcr.nju.edu.cn/open-webui/open-webui:main
What you will run into
After deploying Open WebUI with Docker, the page keeps showing "Ollama not connected" and the model list is empty; inside the container, localhost:11434 returns Connection refused.
The most common cause: following a "local install" tutorial and setting OLLAMA_BASE_URL to http://localhost:11434 — wrong inside a container.
Why this happens
Open WebUI runs inside a Docker container, where localhost is the container itself, not the host.
Ollama listens on the host's 127.0.0.1:11434 by default; nothing listens on localhost:11434 inside the container → connection refused (measured: Errno 111 Connection refused).
To reach the host's Ollama, use the host address as seen from the container network:
| Environment | Host address | Notes |
|---|---|---|
| Docker Desktop (Windows/macOS) | host.docker.internal | available by default |
| Linux Docker engine | host.docker.internal | needs --add-host host.docker.internal:host-gateway (measured: Docker 29.1.3 maps it by default; adding explicitly is harmless) |
| docker compose | host.docker.internal | use extra_hosts: ["host.docker.internal:host-gateway"] |
Note: newer Open WebUI uses the plural env var OLLAMA_BASE_URLS (older docs use singular OLLAMA_BASE_URL); wrong variable name also fails to connect.
Open WebUI runs in a container and Ollama runs on the host — the network-namespace rule "localhost inside a container is the container itself" (see docker-host-access) shows up here directly as Connection refused.
The config layer has a version-evolution trap too: newer Open WebUI uses the plural key OLLAMA_BASE_URLS (older versions used singular OLLAMA_BASE_URL) — a wrong key name fails silently, and the UI still reports "cannot connect".
Deterministic takeaway: on connection failure, first separate "addressing layer" from "config-key layer" — if curl http://host.docker.internal:11434 works inside the container, addressing is fine and the problem is in Open WebUI's key/value (URL with http:// prefix, plural key name);
Docker Desktop injects host.docker.internal by default while Linux engines need --add-host host.docker.internal:host-gateway; after changing env vars, restart the container (env is only read at startup).
Step by step
1. Confirm it is the "in-container address" issue (30-second check) — Required (confirm before touching anything)
docker exec open-webui python3 -c "import urllib.request
for u in ['http://localhost:11434/api/version', 'http://host.docker.internal:11434/api/version']:
try: print(u, '-> OK:', urllib.request.urlopen(u, timeout=5).read.decode.strip)
except Exception as e: print(u, '-> FAIL:', str(e)[:60])"
Measured output shape: localhost:11434 -> FAIL: Connection refused, host.docker.internal:11434 -> OK: {"version":"0.32.14"}. Match = this pit.
2. Check the container start arguments — Diagnose (missing --add-host / wrong var name?)
docker inspect open-webui — look at Config.Env for OLLAMA_BASE_URLS pointing to localhost, and HostConfig.ExtraHosts for a host-gateway mapping (Linux engine).
3. Fix per the table and recreate — Required (recreate applies the fix)
- Value:
http://host.docker.internal:11434(no trailing slash); - Variable: use
OLLAMA_BASE_URLS(plural) on new versions; - Linux: add
--add-host host.docker.internal:host-gateway; compose usesextra_hosts.
4. Verify — Required (check from inside and outside the container)
- Container view:
host.docker.internal:11434returns the Ollama version (measured); - Page: after refresh, the model dropdown lists the host Ollama models (tool-side integration measured: model discovery passed).
How to confirm it works
docker exec open-webui python3 -c "import urllib.request; print(urllib.request.urlopen('http://host.docker.internal:11434/api/tags', timeout=5).read[:200])" returns the model list;
the page model dropdown shows host models (e.g., qwen2.5-0.5b, nomic-embed-text).
Mirror case: external devices / other containers can't reach Ollama
The mirrored trap: the address in the UI is correct, but the Ollama server itself only listens on 127.0.0.1 — a phone on the LAN, another machine, another container, or a remote IDE all fail with connection refused.
Ollama binds loopback by default; to expose it you must change the listen address:
# Server side: listen on all interfaces (LAN / container networks reachable)
OLLAMA_HOST=0.0.0.0:11434 ollama serve
# systemd install: add to [Service] in /etc/systemd/system/ollama.service
# Environment="OLLAMA_HOST=0.0.0.0:11434"
# Docker install: add -e OLLAMA_HOST=0.0.0.0:11434
Verify from outside: curl http://<host-ip>:11434/api/version returns {"version":"..."}.
Two caveats: 0.0.0.0 means the API is open to the LAN (ollama has no auth by default — anyone can list models / run inference; don't expose it in production);
older releases had a regression that bound localhost only (ollama/ollama#12053, fixed in v0.11.5/0.11.6) — upgrading is also a fix.
Other environments
| Environment | Notes |
|---|---|
| Variable name | New versions use plural OLLAMA_BASE_URLS; old tutorials with singular OLLAMA_BASE_URL may not take effect |
| Linux engine | host.docker.internal needs --add-host host.docker.internal:host-gateway; Docker 29.1.3 measured default mapping, explicit add harmless |
| docker compose | environment + extra_hosts: ["host.docker.internal:host-gateway"] |
| UI behavior | Open WebUI connects to Ollama lazily; anonymous requests/logs may show no error — trust the in-container measurement |
| Not measured | Docker Desktop (Windows/macOS) default host.docker.internal behavior (per official mechanism) |
Symptom
Docker-deployed Open WebUI shows "Ollama not connected" with an empty model list; accessing localhost:11434 from inside the container is refused.
Cause
localhost inside a container is the container itself, not the host; OLLAMA_BASE_URLS pointing to localhost:11434 cannot reach the host's Ollama. Use host.docker.internal instead (Linux engines need a host-gateway mapping).
Solution
- Measure both addresses from inside the container: localhost refused, host.docker.internal reachable;
- Recreate the container:
-e OLLAMA_BASE_URLS=http://host.docker.internal:11434(plural var on new versions); - Linux: add
--add-host host.docker.internal:host-gateway(compose:extra_hosts); - Refresh the page and confirm the model list appears.
Verification Evidence
- Measured (2026-08-30, WSL2 Ubuntu + Docker 29.1.3 + ollama 0.32.14): isolated container (port 3001 + separate volume, untouched tool-side container) — inside it
localhost:11434→Errno 111 Connection refused;host.docker.internal:11434→{"version":"0.32.14"}. Anonymous/api/modelsreturns 401 (lazy connect + login session required); the UI "not connected" banner was not captured; mechanism fully verified. local repro log 2026-08-30. - Tool-side integration evidence (2026-08-30, local repro log 2026-08-30):
--add-host=host.docker.internal:host-gateway+OLLAMA_BASE_URLS=http://host.docker.internal:11434container healthy;docker exec/api/tagspassed; open-webui model discovery passed. - Not measured: Docker Desktop (Windows/macOS) default host.docker.internal behavior (per official docs).
Related canonicals
Read in order: precondition -> same root / same domain / related:
- Related (similar errors, different cause):
- Open WebUI RAG retrieval not working / embedding misconfig (RAG_OLLAMA_BASE_URL is a separate key: chat connected != retrieval connected)
- Forgot the admin password / can't log in (WebUI account/login layer)
- ollama reports "could not connect" (first confirm the ollama server itself is running)
Applicable tools (2)
This problem is linked from the tool pages below — reachable from either side.
open-webuidockerBundled solutions (combos)
This problem is part of the following verified bundles.
Source & evidence
← Local LLM domain | Problem Catalog Experience | Facing another issue? Go to the Helpdesk