Run Ollama in Docker with copy-ready run and compose files for CPU, NVIDIA and AMD ROCm, a persistent model volume, env vars, and why Macs get no GPU in Docker.
To run Ollama in Docker, start the official ollama/ollama image with a named volume on /root/.ollama and port 11434. For an NVIDIA GPU, install the NVIDIA Container Toolkit and add --gpus=all (or a deploy.resources device reservation in Compose). For AMD, use the ollama/ollama:rocm tag and pass /dev/kfd and /dev/dri. Docker on macOS has no GPU access, so Mac users should run Ollama natively.
- ollama/ollama (CPU, NVIDIA, Vulkan); ollama/ollama:rocm (AMD)
- /root/.ollama
- 11434
- Not available (no passthrough)
Key takeaways
- The CPU one-liner is docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama. The volume is what keeps your models across container rebuilds.
- NVIDIA needs the host driver plus the NVIDIA Container Toolkit. If docker run --rm --gpus all ubuntu nvidia-smi fails, Ollama will not see the GPU either.
- AMD needs the :rocm tag and the /dev/kfd and /dev/dri devices. The default image also bundles Vulkan, which uses the same device mounts.
- Docker Desktop on macOS has no GPU passthrough, so a containerized Ollama on a Mac runs on CPU. Native Ollama uses Metal.
- The image sets OLLAMA_HOST=0.0.0.0:11434, so a plain -p 11434:11434 exposes the API on every host interface. Bind to 127.0.0.1 unless you mean to share it.
Ollama in Docker comes down to three choices: which image tag, which devices the container gets, and where the models live. Get those right and the same ollama/ollama container runs on a laptop CPU, an NVIDIA workstation or an AMD box with one changed line. Everything below comes from Ollama’s own Docker docs and Dockerfile, NVIDIA’s and Docker’s docs, and GitHub reports from people running it.
How do you run Ollama in Docker?
The CPU-only command from Ollama’s Docker docs is one line:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollamaThree parts matter:
-v ollama:/root/.ollamacreates a named volume. Models, keys and the manifest live there, so you can delete and recreate the container without downloading 20 GB again.-p 11434:11434publishes the API. The Dockerfile setsOLLAMA_HOST=0.0.0.0:11434inside the image, and Docker publishes to all host addresses unless you name one. For a dev box, use-p 127.0.0.1:11434:11434instead.- The image’s entrypoint is
/bin/ollama serve, so the container is the server. You talk to it withdocker execor over HTTP.
The same thing as a Compose file, which is what most people keep in a repo:
services:
ollama:
image: ollama/ollama
container_name: ollama
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
restart: unless-stopped
volumes:
ollama:Running on CPU is fine for small models and for CI. One container-specific catch: a GitHub report found that Ollama sizes its thread pool from the host’s core count and ignores a Compose cpus: limit. On an 8-vCPU host with the container capped at 4 CPUs, llama3.2:3b ran at 0.27 tok/s with the default 8 threads and 12.07 tok/s with num_thread set to 4 (issue #17916, community report on Ollama 0.32.15). If you cap CPUs, set num_thread to match in a Modelfile or in the request options.
How do you give the Ollama container an NVIDIA GPU?
Install the NVIDIA driver on the host, install the NVIDIA Container Toolkit, register it with Docker, then add --gpus=all. The driver stays on the host. The container only gets access to it.
On Debian or Ubuntu, the steps from Ollama’s docs and the NVIDIA install guide are:
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey \
| sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -fsSL https://nvidia.github.io/libnvidia-container/stable/deb/nvidia-container-toolkit.list \
| sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' \
| sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart dockerOn Fedora or RHEL, add the .repo file from the same NVIDIA URL and run sudo dnf install -y nvidia-container-toolkit. Before you touch Ollama, run NVIDIA’s sample workload:
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smiIf that prints your card, start Ollama with the GPU:
docker run -d --gpus=all -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollamaOllama Docker Compose with an NVIDIA GPU
In Compose, the documented way is a device reservation under deploy.resources (Docker Compose GPU docs):
services:
ollama:
image: ollama/ollama
container_name: ollama
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
restart: unless-stopped
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
ollama:Rules from Docker’s docs: capabilities is required, and count and device_ids are mutually exclusive. To pin Ollama to specific cards, replace count: all with device_ids: ['0'] using the IDs from nvidia-smi. Recent Compose versions also accept the shorter gpus: all service attribute (Compose file reference). Older tutorials use runtime: nvidia, which only works when that runtime is registered in Docker’s daemon.json; the device reservation is the form Docker documents.
On NVIDIA Jetson boards, the docs say Ollama can’t detect the JetPack version, so pass -e JETSON_JETPACK=5 or 6. Docker Desktop on Windows works the same way through WSL2, per the Ollama FAQ.
How do you use an AMD GPU with Ollama in Docker?
Use the ollama/ollama:rocm tag and pass the two AMD device nodes, /dev/kfd (the compute interface) and /dev/dri (the GPU render nodes). The run command from the docs:
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama:rocmAs Compose:
services:
ollama:
image: ollama/ollama:rocm
container_name: ollama
devices:
- /dev/kfd:/dev/kfd
- /dev/dri:/dev/dri
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
restart: unless-stopped
# environment:
# - HSA_OVERRIDE_GFX_VERSION=10.3.0 # only for cards ROCm doesn't list
volumes:
ollama:The host needs the ROCm v7 driver (GPU docs); the Dockerfile currently builds against ROCm 7.2.1. For a card that ROCm doesn’t officially target, the docs suggest HSA_OVERRIDE_GFX_VERSION set to the nearest supported target (their example: an RX 5400 runs as 10.3.0). On SELinux distros, the docs say containers may be blocked from the devices until you run sudo setsebool container_use_devices=1 on the host. Card support lists and ROCm-versus-Vulkan trade-offs are in our local LLM on AMD GPU guide.
The default ollama/ollama image also bundles Vulkan, enabled when the container can see GPU devices. That gives Intel and older AMD GPUs a path: pass /dev/dri (and /dev/kfd for AMD) to the default image. Set OLLAMA_VULKAN=0 to turn it off or GGML_VK_VISIBLE_DEVICES to pick devices.
We build CandorNo GPU? Use a hosted model
Uncensored AI, right in your browser.
Candor runs open models with refusals removed, so it answers the questions other assistants deflect. New accounts get free credits, no card needed.
Try Candor freeCan you use the GPU with Ollama in Docker on a Mac?
No. The Ollama FAQ says GPU acceleration “is not available for Docker Desktop in macOS due to the lack of GPU passthrough and emulation.” Docker on a Mac runs Linux containers in a VM, and the VM sees no Apple GPU, so Ollama inside it falls back to CPU. That applies to Ollama Docker on Apple Silicon too: the arm64 image runs, but only on the CPU cores.
What to do instead:
- Run Ollama natively on macOS, where it uses Metal.
- Keep the rest of the stack in Docker and point it at the host:
http://host.docker.internal:11434. This is the usual layout for Open WebUI with Ollama on a Mac. - If the model must run in a container, Podman’s libkrun provider exposes a virtualized Vulkan GPU. It works but is slower than native, as the numbers below show.
Those figures come from a community benchmark of llama.cpp, the engine under Ollama, not of Ollama itself (llama.cpp discussion #12985). The gap is still the useful part: a container on a Mac gave up about half the generation speed even with the virtual GPU.
Which environment variables and volumes should you set?
Set the model volume always, and a few server variables when the defaults don’t fit. Put them under environment: in Compose so they live with the service. The defaults below are from the Ollama FAQ and the Dockerfile.
| Variable or mount | Default | Set it when |
|---|---|---|
ollama:/root/.ollama (volume) | none: models die with the container | Always. Use a bind mount such as ./models:/root/.ollama to keep models on a chosen disk |
OLLAMA_HOST | 0.0.0.0:11434 in the image | Rarely. Control exposure with the -p binding instead |
OLLAMA_KEEP_ALIVE | 5m | You want a model kept in VRAM between requests (-1) or unloaded at once (0); see Ollama keep alive |
OLLAMA_CONTEXT_LENGTH | 4096 per the FAQ; larger on 24 GB+ GPUs per the context docs | Coding agents and RAG need longer context |
OLLAMA_NUM_PARALLEL | 1 | Several users or agents share the server; memory scales with parallel × context |
OLLAMA_MAX_LOADED_MODELS | 3 × GPUs, or 3 on CPU | You swap between models and have the memory |
OLLAMA_FLASH_ATTENTION / OLLAMA_KV_CACHE_TYPE | auto / f16 | You want a q8_0 KV cache to fit more context (needs flash attention) |
CUDA_VISIBLE_DEVICES / ROCR_VISIBLE_DEVICES | all | Limit Ollama to some GPUs (UUIDs are more stable than indexes) |
HTTPS_PROXY | unset | Pulls must go through a corporate proxy (the FAQ advises against HTTP_PROXY) |
OLLAMA_NO_CLOUD | unset | Set to 1 for local-only mode with cloud models disabled |
Two notes on volumes. Named volumes land under Docker’s data root, which can fill a small system disk fast. And docker compose down -v deletes the volume with the models in it, so drop the -v unless you mean it. Choosing and moving model directories outside Docker is covered on its own page about Ollama’s model location.
How do you pull and preload models in the Ollama container?
Use the CLI inside the container, or the HTTP API from outside it. Both write to the mounted volume.
docker exec -it ollama ollama pull qwen2.5-coder:7b
docker exec -it ollama ollama run qwen2.5-coder:7b
docker exec ollama ollama listFrom the host, curl http://localhost:11434/api/pull -d '{"model":"qwen2.5-coder:7b"}' does the same thing.
There is no built-in “pull on start” flag. A request for one, issue #3369, has been open since March 2024. The workarounds posted there come in three patterns:
- Bake models into an image. In a Dockerfile, start the server in the background, pull, and stop it:
RUN ollama serve & sleep 5 && ollama pull qwen2.5-coder:7b. This makes images large, but they start ready. - Wrap the entrypoint. A shell script starts
ollama serve &, polls until it answers, pulls the list of models, thenwaits on the server. Kubernetes users in the thread do this in the container command. - Use a one-shot sidecar. A second service that
depends_onOllama runsollama pullagainstOLLAMA_HOST=ollama:11434and exits.
For a team server, pattern 3 keeps the official image untouched, so upgrades stay a docker compose pull. The wider setup (auth, queueing, which runtime) is in self-hosting an LLM for a dev team.
What do developers report in practice?
The recurring problems are about health checks, GPU visibility and Macs, not about Ollama itself.
-
Health checks fail because the image has no curl. A GitHub report found that a Compose healthcheck running
curl -f http://localhost:11434/api/tagsmarked a working container unhealthy, which broke Traefik routing, becausecurlisn’t in the image (issue #9781, closed as a duplicate of #5389). The current Dockerfile still installs onlyca-certificates,libvulkan1andlibopenblas0. One public Compose stack switched its check to theollamabinary, which is always present (growlf/ai-stack PR #17):healthcheck: test: ["CMD", "ollama", "list"] interval: 30s timeout: 10s retries: 5 -
nvidia-smi working is not proof Ollama uses the GPU. In a Reddit thread, a user got an RTX 3060 working in Compose only after adding the device reservation, and a reply pointed out that
nvidia-smiinside the container proves visibility, not use: checkollama psand GPU memory while generating, and confirm/dev/nvidia-uvmexists on the host (thread). Ollama’s GPU docs separately note that after a Linux suspend and resume, reloadingnvidia_uvmbrings the GPU back. -
Mac users notice the CPU fallback quickly. A Hacker News commenter called losing Metal in Docker “a deal breaker” for local model work on a Mac (HN comment).
If the container starts but ollama ps still shows 100% CPU, the diagnosis is the same as outside Docker, and Ollama not using GPU walks through it.
FAQ
How do I update Ollama in Docker without losing models?
Pull the new image and recreate the container with the same volume: docker compose pull && docker compose up -d. Models live in the ollama volume, not the container, so they survive. Avoid docker compose down -v.
Where are Ollama models stored in Docker?
Inside the container they’re under /root/.ollama/models. On a Linux host, a named volume lives under Docker’s data root, typically /var/lib/docker/volumes/<name>/_data. Compose prefixes the volume with the project name (for example myproject_ollama), so run docker volume ls, then docker volume inspect <name> for the exact path.
How do I connect another container to Ollama in Docker Compose?
Put both services in the same Compose file and use the service name as the host: http://ollama:11434. From a container to Ollama running natively on the host, use http://host.docker.internal:11434.
Is the Ollama Docker image different for AMD GPUs?
Yes. ROCm needs the ollama/ollama:rocm tag. The default ollama/ollama image covers CPU, NVIDIA (CUDA) and Vulkan.
Does Ollama in Docker work on Windows?
Yes, through Docker Desktop with the WSL2 backend. The Ollama FAQ lists Linux and Windows with WSL2 as the platforms where GPU acceleration in Docker works with an NVIDIA card.
We build CandorSkip the setup
Want an uncensored model without hosting one?
Candor (candorai.dev) is an uncensored AI chat app that runs in your browser: it answers the questions mainstream assistants dodge, on health, money, law and work, without the lecture. New accounts get free credits, no card needed.
Facts from candorai.dev, checked Nov 10, 2026. Candor never changes how we rank or review models. Disclosure.
Sources (10)
- Docker, Ollama documentation
- FAQ (environment variables, proxy, GPU in Docker), Ollama documentation
- Hardware support (GPU), Ollama documentation
- Ollama Dockerfile (ENV and ENTRYPOINT), ollama/ollama on GitHub
- Context length, Ollama documentation
- Installing the NVIDIA Container Toolkit, NVIDIA documentation
- Enable GPU support, Docker Compose documentation
- Port publishing and mapping, Docker documentation
- M-series Macs running llama.cpp in GPU-accelerated containers, ggml-org/llama.cpp discussion #12985
- Default n_threads ignores cgroup CPU quota and cpuset, ollama/ollama issue #17916
Written by Refusal Rate editors from papers, model cards, official docs and pricing pages. Anything we ran ourselves is labeled as our own test, with the hardware and settings. Our method.