wget: can't connect to remote host: Connection refused from a container that calls http://localhost:<port> means the request went to the container itself, not to the Ollama server on your Windows host. Use host.docker.internal instead of localhost in the container's URL.

On this PC (Docker Desktop on Windows 11) the same request to http://host.docker.internal:15192 answered, and it reached a host server bound to 127.0.0.1: the Ollama server did not have to listen on any other address. Open WebUI in a container is one place people meet this kind of failure (not tested here).

The error

PS> cmd /c "docker run --rm --name fix9-old-curl1 alpine wget -qO- http://localhost:15192/api/version 2>&1"; echo exit=$LASTEXITCODE
wget: can't connect to remote host: Connection refused
exit=1

At the same moment the host itself answered on that port, listening on loopback only:

PS> curl.exe -s http://127.0.0.1:15192/api/version
{"version":"0.40.14"}
PS> netstat -ano | findstr :15192 | findstr LISTENING
  TCP    127.0.0.1:15192        0.0.0.0:0              LISTENING       38288

Why it happens

A container has its own network namespace, so localhost inside it is the container, and nothing in the alpine container listens on 15192. The Ollama server on the host is fine; the URL points at the wrong machine.

Docker Desktop gives containers a name for the host. In this test it resolved to 192.168.65.254:

PS> cmd /c "docker run --rm --name fix9-old-curl3 alpine getent hosts host.docker.internal 2>&1"
192.168.65.254    host.docker.internal  host.docker.internal

The fix

PS> cmd /c "docker run --rm --name fix9-old-curl2 alpine wget -qO- http://host.docker.internal:15192/api/version 2>&1"; echo exit=$LASTEXITCODE
{"version":"0.40.14"}
exit=0

Change only the host name in the URL your app uses. If the app reads the address from an environment variable, pass it with -e; this run listed the host server's models from inside the container (output cut after the first model):

PS> cmd /c "docker run --rm --name fix9-old-curl4 -e OLLAMA_HOST=http://host.docker.internal:15192 alpine sh -c ""wget -qO- $OLLAMA_HOST/api/tags"" 2>&1"
{"models":[{"name":"qwen3:0.6b","model":"qwen3:0.6b",...

The host server here was bound to 127.0.0.1:15192 and was still reached through host.docker.internal, so there was no need to bind it to 0.0.0.0. Binding the host server to 0.0.0.0 would expose it on your network, so keeping 127.0.0.1 is the safer choice. The default Ollama port is 11434; use the port your own server listens on.

How it was reproduced

A separate Ollama 0.40.14 server was started on the Windows 11 host with OLLAMA_HOST=127.0.0.1:15192 and its own models folder. The requests came from the cached alpine:latest image with its BusyBox wget, on Docker Desktop with engine 29.9.3 and the WSL 2 backend. The container names are the test's own.

Frequently asked

Why can't my Docker container connect to Ollama on localhost?
Inside a container localhost is the container itself. The request never leaves it, so it is refused when nothing in the container listens on that port. Use host.docker.internal in the URL on Docker Desktop.
Does Ollama need to listen on 0.0.0.0 for a container to reach it?
Not in this test. On Docker Desktop for Windows a host server bound to 127.0.0.1:15192 answered requests sent from a container to host.docker.internal:15192.
What address should Open WebUI or my app in Docker use for Ollama on the host?
Replace localhost with host.docker.internal and keep the port your Ollama server listens on, for example http://host.docker.internal:11434 for the default port.

For the ports and the OLLAMA_HOST setting on the host side, see Ollama ports and OLLAMA_HOST. More decoded errors in the Fixes category.