To run Ollama in Docker, start the official ollama/ollama image with a named volume and publish port 11434 on localhost. Use the standard image for CPU or NVIDIA, and use ollama/ollama:rocm with the host’s GPU devices for AMD. Ollama Docker guide · Docker port publishing
The versioned examples use Ollama 0.40.17 image tags. The steps are based on the linked Ollama, Docker, NVIDIA and AMD documentation. No hands-on testing was performed for this guide.
Install Ollama in Docker, step by step
With Docker running, start the CPU container and run Llama 3.2 from inside it. Ollama Docker guide · Docker Hub tags
On Docker Engine 28.0.0 and later, 127.0.0.1 limits access through the published host port to the Docker host. On older releases, devices on the same Layer 2 network segment could still reach ports published to localhost. Docker port publishing
docker pull ollama/ollama:latest
docker run -d -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama
docker exec -it ollama ollama run llama3.2
The ollama volume keeps models between container replacements. The Ollama library lists llama3.2:latest at 2.0 GB. Docker volumes · Llama 3.2 model library
From another terminal on the host, check that the API returns a version in JSON. The next two commands pull the same model through the API and send it a prompt. Version endpoint · Pull endpoint · Generate endpoint
curl http://localhost:11434/api/version
curl http://localhost:11434/api/pull -d '{"model": "llama3.2"}'
curl http://localhost:11434/api/generate -d '{"model": "llama3.2", "prompt": "Why is the sky blue?"}'
For chat, streaming and Python, see Ollama API examples. For CPU sizing or a headless runner comparison, see Ollama without a GPU and Ollama vs LM Studio for headless serving.
The CPU, NVIDIA, ROCm, NVIDIA CDI and Vulkan run commands use the same container name and host port. When switching modes, stop and remove the existing ollama container first. Keep the named volume to reuse downloaded models. Docker container stop · Docker container rm · Docker volumes
docker stop ollama
docker rm ollama
The ollama/ollama image on Docker Hub: tags and sizes
These are the compressed sizes shown on Docker Hub. Docker Hub tags
| Docker Hub tags | Platform | Compressed size |
|---|---|---|
0.40.17 | linux/amd64 | 3.16 GB |
0.40.17 | linux/arm64 | 2.68 GB |
0.40.17-rocm | linux/amd64 | 1.36 GB |
Use a numbered tag to select an image version. Use the pull command for your setup. Docker Hub tags · Ollama Docker guide
docker pull ollama/ollama:0.40.17
docker pull ollama/ollama:0.40.17-rocm
Official Ollama image base and Alpine package
The official Ollama 0.40.17 Dockerfile uses ubuntu:24.04 as its final base. Alpine Linux packages Ollama separately in its edge community repository for x86_64. Alpine lists the package as 0.17.7-r1. Ollama 0.40.17 Dockerfile · Alpine package details
NVIDIA GPU passthrough
On Linux, install the NVIDIA host driver and the NVIDIA Container Toolkit. On Debian or Ubuntu, use these commands to add the package repository, configure the Docker runtime and restart Docker. The restart can interrupt running services. NVIDIA Container Toolkit installation · Ollama Docker guide · Docker restart policies
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 docker
On a DNF-based distribution, follow NVIDIA’s RPM-based toolkit installation instructions, then run the same nvidia-ctk and restart commands. NVIDIA Container Toolkit installation
Check that a container can see the GPU. If nvidia-smi lists your card, start Ollama with --gpus=all, then run the same model command as in the CPU setup. Docker GPU access · Ollama Docker guide
docker run -it --rm --gpus all ubuntu nvidia-smi
docker run -d --gpus=all -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama
To expose just the first GPU, use --gpus device=0. For the first and third GPUs, use --gpus '"device=0,2"'. On Jetson, pass JETSON_JETPACK=5 or JETSON_JETPACK=6 to match the host’s JetPack version. Docker GPU access · Ollama Docker guide
On macOS, use Ollama on Apple Silicon for native GPU acceleration. Ollama’s Docker image runs on the CPU in Docker Desktop on macOS. On Windows, Docker Desktop GPU passthrough to Linux containers requires the WSL 2 backend and an NVIDIA GPU with a driver that supports GPU paravirtualization. Ollama Docker image announcement · Docker Desktop GPU support
nvidia-ctk cdi generate: GPUs by name with CDI
Container Device Interface (CDI) lets the runtime attach GPUs by name. NVIDIA Container Toolkit 1.18.0 and later can generate the spec automatically with nvidia-cdi-refresh. To create it manually and list the device names, run these commands. NVIDIA CDI guide
sudo nvidia-ctk cdi generate --output=/var/run/cdi/nvidia.yaml
nvidia-ctk cdi list
Docker Engine enables CDI by default for Linux containers starting in 28.3.0. Its default spec directories are /var/run/cdi and /etc/cdi. Use the name from the list as the value for --device. Docker run reference · Docker daemon reference · NVIDIA CDI guide
docker run -d --device nvidia.com/gpu=all -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama
For Compose, put the same name under the service’s devices list. Compose Container specification · NVIDIA CDI guide
devices:
- "nvidia.com/gpu=all"
After a driver removal or MIG reconfiguration, regenerate the spec with sudo systemctl restart nvidia-cdi-refresh.service on systems that use the refresh service. If a CDI name fails to resolve, nvidia-ctk --debug cdi list shows errors loading the spec. NVIDIA CDI guide
AMD GPU passthrough with ROCm
For a supported AMD GPU on Linux, install the ROCm v7 host driver and use the rocm image. On the host, /dev/kfd is the shared compute interface and /dev/dri contains the GPU render nodes. Ollama GPU compatibility · AMD ROCm containers · Ollama Docker guide
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama:rocm
Check your exact model in the Linux compatibility table, which covers selected Radeon RX, Radeon PRO, Ryzen AI and Instinct GPUs. If you have multiple AMD GPUs, run rocminfo to list the devices. Set ROCR_VISIBLE_DEVICES in the container to the GPU’s UUID when available, or use its numeric device ID. Ollama GPU compatibility
For unsupported AMD GPUs on Linux, Ollama documents an experimental override. The Radeon RX 5400 example sets HSA_OVERRIDE_GFX_VERSION=10.3.0 so Ollama tries the gfx1030 target. Pass that variable with -e HSA_OVERRIDE_GFX_VERSION=10.3.0 for that specific GPU. Ollama GPU compatibility · Docker run reference
Still choosing a card? The GPU buying guide compares them by VRAM and bandwidth.
The AMD Compose service uses HOST_PATH:CONTAINER_PATH for the two device mappings. Save the file, then follow the same startup commands as in the NVIDIA Compose section. Compose Container specification
services:
ollama:
image: ollama/ollama:0.40.17-rocm
container_name: ollama
restart: unless-stopped
devices:
- "/dev/kfd:/dev/kfd"
- "/dev/dri:/dev/dri"
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
volumes:
ollama:
name: ollama
AMD CDI spec with amd-ctk
With CDI enabled in the container runtime and the AMD driver and Container Toolkit installed, generate and validate the CDI spec. By default, the tool writes /etc/cdi/amd.json. Use a device name from that spec with --device amd.com/gpu=<entry>. AMD Container Toolkit CDI guide
sudo amd-ctk cdi generate
sudo amd-ctk cdi validate
Vulkan on linux/amd64
The linux/amd64 build of the standard Ollama 0.40.17 image includes the Vulkan backend and enables it by default when the container can access the GPU devices. For the AMD device paths shown below, use the numbered tag ollama/ollama:0.40.17. Set OLLAMA_VULKAN=0 to disable Vulkan or use GGML_VK_VISIBLE_DEVICES to select GPUs. Ollama 0.40.17 Dockerfile · Ollama Docker guide · Docker Hub tags
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama:0.40.17
Ollama Docker not using GPU: confirm it landed
Run a model before checking where it loaded. In the ollama ps output, the PROCESSOR column shows 100% GPU when the whole model is in GPU memory. A CPU/GPU split means only part of the model loaded onto the GPU. Ollama FAQ
docker exec -it ollama ollama ps
For a programmatic check, /api/ps lists loaded models and reports their VRAM use in bytes as size_vram. List running models API reference
curl http://localhost:11434/api/ps
If you expected GPU offload and see CPU usage, use docker logs ollama to look for GPU discovery errors. For NVIDIA, repeat the nvidia-smi container check above. If Ollama fails to discover an NVIDIA GPU after Linux resumes from suspend, Ollama documents reloading the nvidia_uvm driver. Docker logs reference · Ollama troubleshooting · Ollama GPU compatibility
For model fit and partial offload, see Ollama not using GPU and the VRAM sizing guide.
Ollama Docker Compose with a restart policy
Save this NVIDIA example as compose.yaml or use the AMD service above. For CPU only, use this example without the deploy block. The GPU reservation requires capabilities: [gpu], and you can specify either count or device_ids. Compose services reference · Docker Compose GPU support
After a successful container start, the unless-stopped policy restarts the container when Docker restarts unless you stopped it. The volume’s explicit name reuses the same ollama volume as the docker run example. The port remains bound to the host’s loopback address. Docker restart policies · Compose volumes · Compose Workload specification
services:
ollama:
image: ollama/ollama:0.40.17
container_name: ollama
restart: unless-stopped
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
ollama:
name: ollama
Run these commands from the directory containing the Compose file. If you already started an ollama container with docker run, use the stop and remove commands above before starting Compose. Docker Compose up · Docker Compose exec · Ollama Docker guide
docker compose up -d
docker compose exec ollama ollama run llama3.2
With Docker Compose 2.30.0 or later, you can use gpus: all under the NVIDIA service in place of the example’s all-GPU reservation. Compose Container specification
Build your own Ollama Dockerfile
If your HTTPS proxy uses a self-signed certificate, extend the official image with the certificate as shown below. Put my-ca.pem alongside the Dockerfile and build the image. Ollama FAQ · Docker build reference
FROM ollama/ollama:0.40.17
COPY my-ca.pem /usr/local/share/ca-certificates/my-ca.crt
RUN update-ca-certificates
docker build -t ollama-with-ca .
For preloading a model at build time, the upstream issue shows a workaround that starts the server in the same build step. Here it is with llama3.2. To pull the model at runtime, use the API example above with the named volume. Ollama issue #5385 · Ollama Docker guide · Docker volumes
FROM ollama/ollama:0.40.17
RUN ollama serve & sleep 10 && ollama pull llama3.2
By default, an empty named volume mounted at /root/.ollama receives the image’s files from that path. A non-empty volume hides the image’s files at that mount path. Docker volumes
Bind port 11434 to localhost
Keep the host IP in 127.0.0.1:11434:11434. Publishing 11434:11434 without a host IP binds to all interfaces by default. Ollama’s local API requires no authentication. Docker port publishing · Ollama API authentication · Ollama FAQ
FAQ
How do I update the Ollama Docker image without losing models?
Pull the new numbered tag from Docker Hub, stop and remove the old container using the commands above, then rerun the original launch command with the new image tag. Keep -v ollama:/root/.ollama and use the version check above to confirm the upgrade. Docker Hub tags · Docker volumes · Version endpoint
Where does the Ollama Docker container store models?
The examples mount the ollama volume at /root/.ollama inside the container. On the host, run docker volume inspect ollama and look for Mountpoint. Ollama Docker guide · Docker volume inspect
Can I run Ollama Docker with an AMD GPU on Windows?
For AMD acceleration through ROCm on Windows, run Ollama natively with a supported GPU and an AMD ROCm v7 / HIP7-capable driver. Docker Desktop’s GPU passthrough to Linux containers on Windows requires NVIDIA. Ollama GPU compatibility · Docker Desktop GPU support