Skip to content

Open WebUI Cannot Connect to Local Ollama: A Layer-by-Layer Guide to connection refused

Scope: Ollama installed and ollama run works on the host, but Open WebUI shows an empty model list, Failed to fetch models, or its container log repeats Get "http://...:11434/api/tags": dial tcp ...: connect: connection refused. Four layers - host, listener, container address, cross-origin - with copyable commands and interpretation notes.

Short answer: connection refused is a network-layer signal, not a model-loading failure and not a broken Open WebUI. It means "the target IP is reachable, but no process accepts connections on that port, or the connection was explicitly rejected". So work outward from the nearest network point: first confirm Ollama is alive and listening on the host, then that its listen address is one a container can reach, then that the URL inside the container points at the host rather than itself, and only finally look at browser cross-origin issues. The Ollama official FAQ and Docker docs are the sources every parameter name and command here was checked against. Wherever "verify against your environment" appears, behavior varies with OS, Docker version, and network topology.

1. Read the error first: do not start with the model

The first step is to layer the error. Connection refused means the TCP connection was explicitly rejected by the target - usually nothing is listening on that port on the target host, or a firewall actively rejected it. It differs from a connection timeout (packets went unanswered) and from HTTP-level 404 or 500 errors. So when the Open WebUI log says dial tcp ...: connect: connection refused, do not pull models, do not rename the model in Open WebUI, and do not reinstall - answer three network questions: is the Ollama process running? What address and port is it listening on? Where does a request from the container actually arrive?

Hold on to that criterion and re-run the same command at each layer, so you avoid "changed a bunch of things and do not know which one fixed it".

2. Layer one: prove it on the host - is Ollama listening?

First prove the Ollama service itself is healthy. On the host (not inside a container) run:

curl http://localhost:11434/api/tags

Whether the host returns a JSON model list is the precondition for everything else. If this fails, the problem is Ollama itself (not started, port taken, wrong bind address) and has nothing to do with Open WebUI. If it works, check the listening address:

# on Linux
ss -tuln | grep 11434
# or
netstat -tuln | grep 11434

The official FAQ states plainly: "Ollama binds 127.0.0.1 port 11434 by default". 127.0.0.1 is loopback, reachable only from the machine itself. Packets arriving from another machine or a container at the host's port 11434 will not be handed to Ollama if the service is bound to loopback. So if ss shows 127.0.0.1:11434 rather than 0.0.0.0:11434, you have already found half the root cause. By the way, the FAQ also notes the local API requires no authentication and anyone reaching the port can use your models - remember this when opening the listener in section 3.

3. Layer two: make Ollama listen on a reachable address (OLLAMA_HOST)

Once the default bind is known to be loopback, the fix is to change it. The FAQ documents the OLLAMA_HOST environment variable and gives a Linux systemd example: add Environment="OLLAMA_HOST=0.0.0.0:11434" under [Service], then systemctl daemon-reload and systemctl restart ollama. On Windows, edit the user environment variable OLLAMA_HOST in Settings, quit the tray app, and relaunch from the Start menu. After any change, re-run ss -tuln | grep 11434 and only call it done when it shows 0.0.0.0:11434.

# Linux systemd override (official FAQ example)
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
# then
# systemctl daemon-reload
# systemctl restart ollama

Separate two things: 0.0.0.0 means "listen on all interfaces" and solves reachability; it has no authentication. Official security guidance is to restrict the port to trusted networks - a container bridge, host gateway, or local loopback are fine - and never publish 11434 to the public internet or forward it on a router. If Open WebUI and Ollama run on the same machine, opening the listener to 0.0.0.0 is necessary (containers arrive via a bridge), and Docker's default isolation usually keeps this safe enough. Exact network topology and firewall rules vary - verify against your environment.

4. Layer three: addresses inside the container - localhost is not the host

This is the most frequent trap: inside a container, localhost means the container itself, not the host. So even with Ollama on 0.0.0.0, if the Open WebUI container is pointed at http://localhost:11434, the request hits the container's own port 11434, where nothing lives, and is immediately refused. The right approach is to let the container reach the "host address"; the official Docker docs use the special hostname host.docker.internal:11434 in their example of a container connecting to Ollama on the host.

# verify from inside the Open WebUI container that the host Ollama resolves and answers
docker exec -it open-webui curl http://host.docker.internal:11434/api/tags

On Docker Desktop (Mac, Windows), host.docker.internal usually works out of the box; on plain Linux Docker Engine, that hostname is not resolved by default, so add an explicit mapping when starting the container:

--add-host=host.docker.internal:host-gateway

This maps host.docker.internal to the host gateway IP (host-gateway is a Docker-provided special value), letting the container resolve and reach the host. Then curl again from inside the container; a returned model list means the network layer is healthy. Note this only fixes name resolution - if section 2 did not change Ollama to listen on 0.0.0.0, the request reaching the host gateway is still refused. Both must be done. A lazier path is --network host for the container (Linux only), which shares the host network namespace so localhost:11434 really is the host Ollama; that sacrifices network isolation, so the explicit mapping above is preferred in production.

The exact availability and syntax of host.docker.internal and host-gateway vary with Docker version and platform, so verify against your environment and the official Docker docs; no more version-specific detail is written here.

5. Layer four: browser cross-origin (OLLAMA_ORIGINS)

If curl inside the container can already fetch /api/tags but the browser still shows connection or CORS errors, the problem has moved from networking to the browser's same-origin policy. The official FAQ says Ollama allows cross-origin requests from 127.0.0.1 and 0.0.0.0 by default; additional origins are configured with the OLLAMA_ORIGINS environment variable, and browser extensions need their origin pattern explicitly allowed - the FAQ gives an example allowing all Chrome, Firefox, and Safari extensions.

OLLAMA_ORIGINS=chrome-extension://*,moz-extension://*,safari-web-extension://* ollama serve

For most Open WebUI deployments the front end talks to Ollama via server-side forwarding and browser CORS is not triggered; OLLAMA_ORIGINS matters when a third-party browser page or extension calls Ollama directly. Diagnose by checking whether the error mentions CORS or Access-Control-Allow-Origin: if so, examine this layer; if not, return to networking. Keep OLLAMA_HOST (reachability) and OLLAMA_ORIGINS (cross-origin allowlist) in separate mental boxes - two independent switches, do not change both at once.

6. A worked convergence example

Chain the layers into one reusable procedure. Suppose the Open WebUI container log reports dial tcp 172.17.0.1:11434: connect: connection refused:

Step 1, on the host curl http://localhost:11434/api/tags - works, so Ollama is alive. Step 2, ss -tuln | grep 11434 shows 127.0.0.1:11434, so it is bound to loopback only - one root cause. Step 3, set OLLAMA_HOST to 0.0.0.0:11434 via a systemd override per the FAQ, restart, and recheck ss shows 0.0.0.0. Step 4, from the container curl http://host.docker.internal:11434/api/tags - if name resolution fails, add the --add-host mapping and recreate the container; if refused with resolution fine, go back to step 3 and confirm the listener really changed. Step 5, if curl works inside the container but the browser still fails, look for CORS wording in the log before deciding on OLLAMA_ORIGINS. Change one variable and test one hypothesis at a time, so you know exactly which layer fixed it.

7. Acceptance checklist before calling it done

  • On the host, curl http://localhost:11434/api/tags returns a JSON model list
  • ss -tuln | grep 11434 (or netstat) shows Ollama listening on 0.0.0.0:11434, not only 127.0.0.1
  • OLLAMA_HOST was set the way the official FAQ describes, and the listener was rechecked after restart
  • Inside the Open WebUI container, curl http://host.docker.internal:11434/api/tags works; on plain Linux an --add-host=host.docker.internal:host-gateway or equivalent is configured
  • The container points at the host address, not its own localhost
  • If the browser error mentions CORS, OLLAMA_ORIGINS was used to allow the needed origin; otherwise it was left alone
  • Port 11434 is not exposed to public or untrusted networks; the OS, Docker version, and network topology at the time were recorded (verify against your environment)

One last principle: connection refused means "the network is not connected", not "the model is not installed". Verify host, listener, container address, and browser as four separate layers, and refusal issues usually converge in minutes. For Ollama server configuration see the Ollama Deployment Handbook on this site, Inference Engine Selection for port conflicts and engine choices, and Ollama Enterprise Deployment for intranet deployments.