Ollama in Docker: GPU Setup, Compose File and Open WebUI
By LLM Hardware team · Methodology ·
LLM Hardware team
To run Ollama in Docker with an NVIDIA GPU, install the NVIDIA Container Toolkit, register it with Docker using nvidia-ctk runtime configure --runtime=docker, restart Docker, and start the ollama/ollama image with --gpus=all. Mount a volume at /root/.ollama so models survive container rebuilds, and publish port 11434. AMD cards use the ollama/ollama:rocm tag with /dev/kfd and /dev/dri passed through. Docker Desktop on a Mac cannot pass the GPU into a container, so Mac users run Ollama natively. Once the container runs, size your model with the site formula: an 8B model at Q4 needs about 6.8 GB of VRAM (8 x 0.5 x 1.2 + 2).
This page walks through the toolkit install, the exact docker run lines from the Ollama docs, a compose file that pairs Ollama with Open WebUI, how to confirm the GPU is in use, and the fixes the Ollama troubleshooting docs list when the container falls back to CPU. If you have not installed Ollama before, the Ollama cheat sheet covers the native commands that also work inside the container.
Why run Ollama in a container
A container keeps the Ollama runtime, its GPU libraries and its model store in one removable unit. You upgrade by pulling a new image, you move the setup to another machine by copying a compose file, and you pair it with other containers such as Open WebUI on a shared network. The trade is that the host needs extra plumbing before the container can see the GPU. On Linux that plumbing is the NVIDIA Container Toolkit for NVIDIA cards, or device passthrough for AMD cards. On Windows, Docker Desktop with the WSL 2 backend supports NVIDIA passthrough. On macOS there is no GPU path into containers at all, and the section on Macs below explains what to do instead.
If you want the shortest route to a working local model and do not need containers, how to run LLMs locally and the Windows guide cover native installs. For a comparison of Ollama with a desktop app, see LM Studio vs Ollama.
CPU-only quick start
The Ollama Docker docs start with a command that needs no GPU setup. It runs the image in the background, mounts a named volume called ollama at /root/.ollama, publishes port 11434 and names the container ollama:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama Then run a model inside the container:
docker exec -it ollama ollama run llama3.2 That command pulls llama3.2 on first use and opens an interactive chat. The same container, started with different flags, is what the GPU sections below use. If you remove this container to switch to a GPU run, the named volume keeps the downloaded models, so the next container finds them again. The CPU-only route also has its own RAM math, covered in run an LLM on CPU.
Ollama Docker GPU setup for NVIDIA
Three prerequisites apply before you touch Docker. First, a supported NVIDIA driver on the host: NVIDIA's install guide lists a driver as a prerequisite and prefers your distribution's package manager. Second, a GPU Ollama supports. The Ollama GPU docs give compute capability 5.0 as the floor with driver version 550 or newer, and say cards at compute capability 5.0 through 6.2 need driver 570 or newer. Third, the NVIDIA Container Toolkit, which lets Docker hand the GPU to a container.
Step 1: install the NVIDIA Container Toolkit
On Debian and Ubuntu, the Ollama docs configure NVIDIA's apt repository and install the nvidia-container-toolkit package:
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 On RHEL, Fedora and related distributions, use the yum or dnf route from the same page:
curl -fsSL https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo \
| sudo tee /etc/yum.repos.d/nvidia-container-toolkit.repo
sudo yum install -y nvidia-container-toolkit NVIDIA's own install guide is the reference to check for the current package list. At the time of reading it described installing four toolkit packages pinned to one version through apt, dnf and zypper, while the Ollama docs install the single nvidia-container-toolkit package. Open NVIDIA's page before you copy either set, because repository paths and package versions change.
Step 2: configure Docker to use the NVIDIA runtime
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker NVIDIA's guide says this command updates /etc/docker/daemon.json, and that you restart the Docker service afterward. For rootless Docker the same guide points the command at the user's daemon.json, restarts the user-level Docker service and sets the no-cgroups option in the toolkit config. For Podman, NVIDIA recommends using CDI to reach GPUs, which this page does not cover.
Step 3: confirm Docker can see the GPU
Before pulling the Ollama image, run NVIDIA's sample workload. It starts a throwaway Ubuntu container with the GPU attached and prints the nvidia-smi table:
sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi NVIDIA's page shows the output as an nvidia-smi table listing the driver version, the CUDA version and your GPU. Ollama's troubleshooting page uses a shorter form of the same check, docker run --gpus all ubuntu nvidia-smi, and states that if it fails, Ollama cannot see the NVIDIA GPU either. Fix this layer first. Nothing in the Ollama image can compensate for a runtime that does not expose the card.
Step 4: start Ollama with the GPU
docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama The only change from the CPU command is --gpus=all. If you run Ollama on an NVIDIA JetPack system, the docs add one requirement: Ollama cannot discover the JetPack version, so pass JETSON_JETPACK=5 or JETSON_JETPACK=6 as an environment variable to select version 5 or 6.
AMD GPUs: the ROCm image
AMD cards skip the NVIDIA toolkit. The Ollama docs use a separate rocm tag and pass the kernel's compute and render devices into the container:
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama:rocm Three notes from the Ollama GPU and troubleshooting pages apply to AMD containers. Ollama requires the AMD ROCm v7 driver on Linux. SELinux can block containers from reaching AMD GPU devices, and the docs give sudo setsebool container_use_devices=1 on the host as the fix. And if the container cannot open the devices, find the numeric group IDs on the host and pass them with --group-add:
ls -lnd /dev/kfd /dev/dri /dev/dri/* The GPU docs also say unsupported AMD GPUs may work if you set HSA_OVERRIDE_GFX_VERSION to a close LLVM target, with 10.3.0 as the example for an RX 5400. Treat that as an experiment, not a supported path. For card choice by VRAM, see the best GPU for LLMs.
Vulkan and other options
The Docker docs say Vulkan support is bundled into the default ollama/ollama image and is enabled when the container can access the GPU devices. Their example passes the same two devices as the ROCm command, with the default image:
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama Set OLLAMA_VULKAN=0 to disable Vulkan, or GGML_VK_VISIBLE_DEVICES=<ids> to select specific Vulkan devices. The docs name no other GPU image tags besides the default and rocm.
Ollama Docker Compose file with Open WebUI
The Ollama docs do not ship a compose file, so this one is assembled from three documented sources: the image, volume and port from the Ollama Docker page, the GPU reservation syntax from Docker's Compose GPU page, and the Open WebUI service from Open WebUI's own repository compose file. It is an NVIDIA example. Docker's docs say the capabilities field is required and that the deploy fails with an error without it.
services:
ollama:
image: ollama/ollama
container_name: ollama
restart: unless-stopped
ports:
- "11434:11434"
volumes:
- ollama:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
restart: unless-stopped
depends_on:
- ollama
ports:
- "3000:8080"
environment:
- OLLAMA_BASE_URL=http://ollama:11434
- WEBUI_SECRET_KEY=replace-with-your-own-value
volumes:
- open-webui:/app/backend/data
volumes:
ollama: {}
open-webui: {} Start it and watch the Ollama log for GPU discovery:
docker compose up -d
docker compose logs -f ollama What each part does:
count: allreserves every GPU on the host. Docker's docs accept an integer orall, and say all GPUs are used whencountis unset. To pin a card, replace it withdevice_idsand the ID shown bynvidia-smion the host. The two fields are mutually exclusive.OLLAMA_BASE_URL=http://ollama:11434is the value in Open WebUI's repository compose file. It works because both services share the compose network, so the hostnameollamaresolves to the Ollama container.- The host port 3000 maps to container port 8080 for Open WebUI, matching the quick-start commands. Open it at
http://localhost:3000. - Open WebUI's quick start says to keep the same
WEBUI_SECRET_KEYwhen you recreate the container so users stay logged in, and to point the volume at/app/backend/data, not/app/backend.
For an AMD host, swap the Ollama service for the ROCm image and device passthrough from the previous section and drop the deploy block, which is NVIDIA-specific. The full home-server pattern, including auto-start and remote access, is in the Open WebUI and Ollama always-on home agent guide.
Open WebUI with Ollama in Docker
Open WebUI's quick start uses the image ghcr.io/open-webui/open-webui:main. It offers three setups that matter here:
- Separate containers. Run Ollama as above and Open WebUI as its own container, as in the compose file or the command below.
- The
:cudatag. The page describes it as running Open WebUI's local embedding, reranking and Whisper models on an NVIDIA GPU. It needs the NVIDIA Container Toolkit and is separate from where Ollama runs your chat model. - The
:ollamatag. A single container that bundles Open WebUI and Ollama, with--gpus=alladded for NVIDIA and both volumes mounted. It is convenient, though it ties the two upgrade cycles together.
If Ollama already runs in a container with port 11434 published, start Open WebUI with the documented host-gateway entry and point OLLAMA_BASE_URL at host.docker.internal. This command combines the quick-start flags with the Docker Desktop URL from Open WebUI's connection troubleshooting page:
docker run -d -p 3000:8080 --add-host=host.docker.internal:host-gateway -e OLLAMA_BASE_URL=http://host.docker.internal:11434 -v open-webui:/app/backend/data --name open-webui --restart always ghcr.io/open-webui/open-webui:main When Open WebUI cannot reach Ollama on the host, the Open WebUI docs give two causes and fixes. Ollama listens on 127.0.0.1 by default, so set OLLAMA_HOST=0.0.0.0 and restart it. Or run the Open WebUI container with --network=host and OLLAMA_BASE_URL=http://127.0.0.1:11434, where published ports no longer apply and the interface moves to http://localhost:8080. On Docker Desktop, host networking needs version 4.34 or later and the Enable host networking setting.
Verify the GPU is in use
A container that starts without errors does not prove the model runs on the GPU. Load a model, then check where it landed:
docker exec -it ollama ollama run llama3.2
docker exec -it ollama ollama ps
docker logs ollama The Processor column of ollama ps is the authoritative answer, per the Ollama FAQ:
| Processor value | Meaning | What to do |
|---|---|---|
100% GPU | The model loaded entirely into the GPU. | Nothing. This is the goal. |
100% CPU | The model loaded entirely in system memory. | The container has no GPU access. Work through the troubleshooting list below. |
48%/52% CPU/GPU | The model loaded partly onto both. | The GPU works but the model is larger than free VRAM. Pick a smaller model or quantization. |
On an NVIDIA host you can also run nvidia-smi in a host terminal while a model generates and look for memory in use on the card. Logs are the second source: the troubleshooting page says Ollama logs go to the container's stdout and stderr, readable with docker logs ollama. Setting OLLAMA_DEBUG=1 makes GPU discovery report more detail. A split in ollama ps is a sizing problem, covered in the next section and in the hybrid offloading guide.
Will your model fit? A VRAM note
The site formula is GB = params (billions) x bytes per parameter x 1.2 + 2, with 0.5 bytes at Q4, 1.0 at Q8 and 2.0 at FP16. The 1.2 factor and the extra 2 GB cover activations and a short context. For an 8B model at Q4 that works out to 8 x 0.5 x 1.2 + 2 = 6.8 GB. The table applies the same arithmetic to a few sizes:
| Model size | Quant | Math | Estimated VRAM |
|---|---|---|---|
| 8B | Q4 | 8 x 0.5 x 1.2 + 2 | 6.8 GB |
| 8B | Q8 | 8 x 1.0 x 1.2 + 2 | 11.6 GB |
| 14B | Q4 | 14 x 0.5 x 1.2 + 2 | 10.4 GB |
| 32B | Q4 | 32 x 0.5 x 1.2 + 2 | 21.2 GB |
| 70B | Q4 | 70 x 0.5 x 1.2 + 2 | 44 GB |
Docker adds no VRAM requirement of its own in these docs, so the same numbers apply inside and outside a container. Compare the result with the free VRAM on the card, not the total, because a desktop environment or another process may already hold some. Run your own sizes through the VRAM calculator, check a specific card and model pair with Can I run it, and read Ollama keep_alive if a loaded model keeps holding VRAM after you stop chatting. This site does not benchmark hardware, so it quotes no speed figures.
Troubleshooting Ollama in Docker
The container runs on CPU and ollama ps shows 100% CPU
Start with the runtime check. If docker run --gpus all ubuntu nvidia-smi fails, the NVIDIA Container Toolkit is missing or not configured, and Ollama will not see the card. Repeat steps 1 and 2 above, confirm you restarted Docker, and check that you started the Ollama container with --gpus=all (or the compose reservation). If the sample passes but Ollama still reports CPU, read the container log with docker logs ollama.
GPU discovery errors on Linux
The troubleshooting page says that if Ollama falls back from the GPU to CPU with discovery errors, you can disable systemd cgroup management in Docker by adding this to /etc/docker/daemon.json on the host, then restarting Docker:
{
"exec-opts": ["native.cgroupdriver=cgroupfs"]
} NVIDIA's install guide carries a related warning: on systems using the systemd cgroup driver, running systemctl daemon reload can cause containers to lose GPU access. If a working container loses the GPU later, restarting it is the first thing to try.
NVIDIA driver module and error codes
For NVIDIA initialization failures, the Ollama docs say to check that the nvidia_uvm module is loaded and to reload it if not:
sudo nvidia-modprobe -u
sudo rmmod nvidia_uvm
sudo modprobe nvidia_uvm Initialization failures can appear in the server logs as codes 3, 46, 100 or 999. Setting CUDA_ERROR_LEVEL=50 and retrying produces more diagnostic output.
Docker Desktop on a Mac cannot use the GPU
The Ollama FAQ states that GPU acceleration is not available for Docker Desktop on macOS because of the lack of GPU passthrough and emulation, and Ollama's Docker announcement says to run Ollama as a standalone application outside Docker containers on a Mac. Ollama's GPU docs say it supports GPU acceleration on Apple devices through the Metal API, which the native app uses. You can still run Open WebUI in Docker on a Mac and point it at the native Ollama through host.docker.internal. For the Mac hardware side, see how to run LLMs on a Mac.
Windows with WSL 2
The Ollama FAQ says the Docker container can be configured for GPU acceleration on Linux or on Windows with WSL 2. Docker's Desktop GPU page documents --gpus passthrough as available on Windows with the WSL 2 backend and an NVIDIA GPU. If you only want Ollama on a Windows machine and have no need for containers, the native route in the Ollama Windows setup guide has fewer moving parts.
Models vanish or the volume looks wrong
Every official command mounts a named Docker volume at /root/.ollama. If models disappear after you recreate the container, the new container probably started without -v ollama:/root/.ollama or with a differently named volume. Run docker volume ls to see what exists. The Ollama docs do not discuss bind-mount ownership or permissions, so this page makes no claim about them. A named volume avoids the question because Docker manages it.
Open WebUI cannot find any models
Check OLLAMA_BASE_URL first. In a shared compose file it should be http://ollama:11434. For a host-side or separate-network Ollama it should be http://host.docker.internal:11434 on Docker Desktop. Then confirm the Ollama container has any models: docker exec -it ollama ollama run llama3.2 pulls one if the volume is empty.
FAQ
How do I run Ollama in Docker with an NVIDIA GPU?
Install the NVIDIA Container Toolkit, run sudo nvidia-ctk runtime configure --runtime=docker, restart Docker, then start the container with docker run -d --gpus=all -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama. Check that the model loaded on the GPU with docker exec -it ollama ollama ps.
What does an Ollama docker compose file need for GPU access?
The ollama service needs a deploy.resources.reservations.devices entry with driver: nvidia, a count (or all) and capabilities: [gpu]. Docker requires the capabilities field and returns an error on deploy without it. Add the ollama:/root/.ollama volume and the 11434:11434 port.
Can Ollama use the GPU in Docker Desktop on a Mac?
No. The Ollama FAQ states that GPU acceleration is not available for Docker Desktop on macOS because of the lack of GPU passthrough and emulation. On a Mac, run Ollama as a standalone application outside Docker so it can use Metal.
How do I connect Open WebUI to Ollama in Docker?
If both run in one compose file, set OLLAMA_BASE_URL=http://ollama:11434 on the Open WebUI service, which is the value in the Open WebUI repository compose file. If Ollama runs on the host or in a separate container with a published port, Open WebUI docs suggest OLLAMA_BASE_URL=http://host.docker.internal:11434 on Docker Desktop.
Where does Ollama store models in a Docker container?
In /root/.ollama inside the container. The official commands mount a named volume there with -v ollama:/root/.ollama, so models survive removing and recreating the container.
Why does Ollama fall back to CPU in Docker?
Ollama troubleshooting docs list two common causes on Linux. First, the container runtime is not set up, which you can test with docker run --gpus all ubuntu nvidia-smi. Second, the systemd cgroup driver can cause GPU discovery errors, which the docs fix with native.cgroupdriver=cgroupfs in /etc/docker/daemon.json.
Sources
| # | URL | Claim it supports | Date checked (PT) |
|---|---|---|---|
| 1 | https://docs.ollama.com/docker | Ollama Docker page: CPU-only, NVIDIA (--gpus=all), AMD (ollama/ollama:rocm), Vulkan bundled in the image, and docker exec -it ollama ollama run llama3.2 | 2026-11-22 |
| 2 | https://raw.githubusercontent.com/ollama/ollama/main/docs/docker.mdx | Exact commands for CPU, NVIDIA toolkit apt and yum install, nvidia-ctk runtime configure, ROCm and Vulkan; JETSON_JETPACK=5 or 6; OLLAMA_VULKAN=0; GGML_VK_VISIBLE_DEVICES | 2026-11-22 |
| 3 | https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/install-guide.html | NVIDIA install guide: driver prerequisite, apt, dnf and zypper install paths, Docker configure step, rootless Docker note, Podman and CDI recommendation | 2026-11-22 |
| 4 | https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/latest/sample-workload.html | Sample workload command sudo docker run --rm --runtime=nvidia --gpus all ubuntu nvidia-smi | 2026-11-22 |
| 5 | https://docs.ollama.com/gpu | NVIDIA compute capability 5.0 with driver 550 or newer; ROCm v7 on Linux; SELinux container_use_devices; Vulkan notes; GPU selection variables; Metal on Apple devices | 2026-11-22 |
| 6 | https://docs.ollama.com/troubleshooting | docker logs, cgroupfs driver fix, docker run --gpus all ubuntu nvidia-smi check, nvidia_uvm reload, error codes, CUDA_ERROR_LEVEL=50, AMD --group-add, OLLAMA_DEBUG=1 | 2026-11-22 |
| 7 | https://docs.ollama.com/faq | Docker GPU acceleration on Linux or Windows with WSL2; none on Docker Desktop for macOS; default bind 127.0.0.1 port 11434; ollama ps Processor column values | 2026-11-22 |
| 8 | https://ollama.com/blog/ollama-is-now-available-as-an-official-docker-image | Mac guidance: run Ollama as a standalone application outside Docker containers because Docker Desktop does not support GPUs | 2026-11-22 |
| 9 | https://docs.docker.com/desktop/features/gpu/ | Docker Desktop --gpus passthrough is documented for Windows with the WSL 2 backend and an NVIDIA GPU; macOS is not named | 2026-11-22 |
| 10 | https://raw.githubusercontent.com/docker/docs/main/content/manuals/compose/how-tos/gpu-support.md | Compose GPU reservation syntax: driver, count, device_ids, capabilities; capabilities is required; count and device_ids are mutually exclusive | 2026-11-22 |
| 11 | https://docs.openwebui.com/getting-started/quick-start/ | Open WebUI image ghcr.io/open-webui/open-webui:main, port mapping 3000:8080, data volume /app/backend/data, :cuda and :ollama tags, WEBUI_SECRET_KEY, OLLAMA_BASE_URL | 2026-11-22 |
| 12 | https://github.com/open-webui/open-webui/blob/main/docker-compose.yaml | Open WebUI repository compose file: ollama and open-webui services, OLLAMA_BASE_URL=http://ollama:11434, volumes ollama and open-webui | 2026-11-22 |
| 13 | https://docs.openwebui.com/troubleshooting/connection-error/ | Ollama listens on 127.0.0.1 by default; OLLAMA_HOST=0.0.0.0; --network=host; host.docker.internal:11434 on Docker Desktop | 2026-11-22 |