Ollama Docker Network Setup: Ports, host.docker.internal
Published · 7 min read
Original research brief: . Sources reviewed: .
Looking for an app to help with this? Try Ollama Connect.
Quick answer: Start Ollama in Docker with
-p 11434:11434so the host can reach it on port 11434. From another container, don't uselocalhost; usehttp://host.docker.internal:11434. On Linux without Docker Desktop, add--add-host=host.docker.internal:host-gatewayfirst. If you still get connection refused, checkdocker logsand test/api/tags.
Most Ollama Docker problems are address problems, not model problems. Each container has its own localhost. So an app in one container that calls localhost:11434 is talking to itself, and gets "connection refused". This guide covers the official way to start the container, how other containers reach it, and how to test each layer.
If Ollama is installed directly on your computer rather than in Docker, the Ollama local network setup guide is the better starting point.
How to run Ollama in Docker (official commands)
These commands come from Ollama's Docker documentation and the Docker Hub page. They work on Linux, and on macOS or Windows with Docker installed.
CPU only:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
NVIDIA GPU (Linux, or Windows with WSL2, after installing the NVIDIA Container Toolkit):
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama
AMD GPU (Linux):
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama:rocm
Then run a model inside the container:
docker exec -it ollama ollama run llama3.2
What each part does:
| Flag | What it means |
|---|---|
-d |
Runs the container in the background. |
-v ollama:/root/.ollama |
Keeps downloaded models in a named volume, so they survive a container restart. |
-p 11434:11434 |
Publishes Ollama's port to the host. Without it, the host and your phone cannot reach it. |
--name ollama |
Gives the container a fixed name for docker exec and docker logs. |
--gpus=all |
Gives the container the NVIDIA GPU. |
One Mac note: Ollama's FAQ says GPU acceleration is not available for Docker Desktop on macOS, because Docker there has no GPU passthrough. On a Mac, the native Ollama app can use the GPU; Docker cannot.
Ollama default port in Docker: 11434
Ollama listens on port 11434. The official commands publish the same number on the host with -p 11434:11434. The left number is the host port and the right is the port inside the container.
Check it from the host (macOS, Linux, or Windows with curl):
curl http://localhost:11434/api/tags
A JSON reply with a models list means the container is up and the port is published. An empty list just means you haven't pulled a model yet. For more about the port itself, see Ollama port 11434: default URL and fixes.
Ollama host.docker.internal 11434: reaching the host from a container
This is the most searched Docker problem, and the cause is simple. Picture two common setups:
- Ollama on the host, another app in Docker. For example, Ollama is the native Mac or Windows app, and a chat web UI or workflow tool runs in a container.
- Ollama in Docker, another app in a different container, with Ollama's port published to the host.
In both cases the other container must not use localhost. Ollama's own integration guides tell you to use this base URL when the app runs in Docker (n8n guide, Onyx guide):
http://host.docker.internal:11434
host.docker.internal is a special name for "the computer running Docker". Docker Desktop on macOS and Windows adds it for you.
host.docker.internal on Linux
On Linux servers without Docker Desktop, the name does not exist by default. Ollama's n8n guide gives two fixes. Add a flag when you start the other container (Linux):
docker run --add-host=host.docker.internal:host-gateway ...
Or add this to that service in your Docker Compose file:
extra_hosts:
- "host.docker.internal:host-gateway"
If Ollama itself runs natively on that Linux host, remember it binds to 127.0.0.1 by default. A container may then still be refused, because it arrives from outside loopback. Set OLLAMA_HOST=0.0.0.0:11434 through systemd as shown below.
Ollama not connecting to Open WebUI or another tool
The same rule fixes "ollama not connecting to openwebui" and similar "network problem" errors in chat UIs and workflow tools. Work through this checklist in order:
- The Ollama container is running:
docker psshows it. -
curl http://localhost:11434/api/tagsworks on the host. - The other tool's Ollama URL is
http://host.docker.internal:11434, notlocalhost. - On Linux, the other container has the
host-gatewaymapping. - The URL has no extra path such as
/api/tagsunless the tool asks for one. - Ollama's logs show the request arriving.
Read the logs for the Ollama container (any OS):
docker logs ollama
Ollama's troubleshooting page confirms that in a container the logs go to the container's standard output, which is what docker logs shows.
Setting OLLAMA_HOST when Ollama is not in Docker
OLLAMA_HOST is the setting that changes where Ollama listens. Ollama binds to 127.0.0.1:11434 by default, per the FAQ. You only need it when Ollama runs natively and something outside the machine's loopback needs to reach it, such as a container on Linux or a phone.
Linux (systemd): run systemctl edit ollama.service, then add under [Service]:
[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"
Then reload and restart (Linux):
sudo systemctl daemon-reload
sudo systemctl restart ollama
macOS (Ollama app), then restart the app:
launchctl setenv OLLAMA_HOST "0.0.0.0:11434"
Windows: quit Ollama, search Settings for "environment variables", edit the variables for your account, add OLLAMA_HOST, then start Ollama again from the Start menu.
Using Ollama in Docker behind a proxy
If your network needs an outbound proxy to download models, Ollama's FAQ says to pass it when starting the container (Linux, macOS or Windows):
docker run -d -e HTTPS_PROXY=https://my.proxy.example.com -p 11434:11434 ollama-with-ca
That example uses an image built with the proxy's certificate installed. The FAQ shows how to build it when the proxy uses a self-signed certificate. This is about Ollama reaching the internet, not about letting people reach Ollama.
Reach the Docker Ollama from your phone
Once /api/tags works on the host, the phone needs the host computer's LAN address, such as http://192.168.1.42:11434, not localhost. Test that URL in the phone's browser first. If it fails, check the host firewall and Wi-Fi isolation using the phone connection checklist.
For a chat app, Ollama Connect is our client for the Ollama host you run. It can search the local network for nearby Ollama servers, or you can add the host manually and run its connection diagnostics. It is on iPhone and Android. It does not provide hosted models, so the Docker container above is still doing the work.
Keep the port private
Ollama's authentication docs say the local API does not require authentication. Anyone who can reach port 11434 can use your models. Keep the published port on a network you trust, and never port-forward 11434 on your router. If you want access from outside the house, read how to use Ollama away from home safely.
Related reading
- Ollama local network setup guide
- Best small LLMs to run on a home Mac with Ollama
- Ollama context length and memory when chatting from your phone
Sources
- Docker — Ollama — https://docs.ollama.com/docker
- ollama/ollama image — Docker Hub — https://hub.docker.com/r/ollama/ollama
- FAQ — Ollama — https://docs.ollama.com/faq
- Troubleshooting — Ollama — https://docs.ollama.com/troubleshooting
- Authentication — Ollama — https://docs.ollama.com/api/authentication
- n8n integration — Ollama (GitHub) — https://github.com/ollama/ollama/blob/main/docs/integrations/n8n.mdx
- Onyx integration — Ollama (GitHub) — https://github.com/ollama/ollama/blob/main/docs/integrations/onyx.mdx
Frequently asked questions
- What port does Ollama use in Docker?
- The official Docker command publishes port 11434 with -p 11434:11434, which is the same default port Ollama uses outside Docker. Test it with a request to /api/tags on that port.
- What is host.docker.internal 11434 for Ollama?
- It is the address a container uses to reach Ollama running on the host computer. Ollama's integration guides use http://host.docker.internal:11434 when the other app runs in Docker.
- Why does host.docker.internal not work on Linux?
- Ollama's n8n guide notes that host.docker.internal is not added automatically outside Docker Desktop, such as on Linux servers. Add it with --add-host=host.docker.internal:host-gateway or an extra_hosts entry in Docker Compose.
- Why do I get connection refused from another container?
- Usually the other container is calling localhost, which points at itself, not at Ollama. Use host.docker.internal or the host's LAN address, and check the Ollama container is running with docker logs.
- Does Docker on a Mac use the GPU for Ollama?
- No. Ollama's FAQ says GPU acceleration is not available for Docker Desktop on macOS because there is no GPU passthrough. GPU acceleration in Docker works on Linux, or Windows with WSL2, with the NVIDIA Container Toolkit.
The app behind this guide
Ollama Connect
See the features and screenshots, or open the App Store from this guide.
Related guides
Can You Run Ollama on iPhone or Android? What Works
Is there Ollama for iPhone or Android? Ollama officially runs on macOS, Windows, Linux and Docker. Here is how to use it from your phone instead, step by step.
Ollama Port 11434: Default URL, Changing It and Fixes
Ollama listens on localhost:11434 by default. Learn the default URL, how to change the port on Mac, Windows or Linux, and fix connection refused errors.
Ollama with Claude Code and Codex: Local Model Setup
How to use Ollama with Claude Code and Codex: ollama launch, the manual settings each tool documents, the 64k context window, and the limits of local models.