Ollama Docker Setup Guide — Run Local LLMs in Containers (2026)
Running LLMs locally is powerful. Packaging Ollama with Docker makes the runtime more repeatable, but a container alone does not make it production-ready. This guide walks through Ollama in Docker—from a single service to a stack with GPU passthrough and a web UI. Browse the local AI hub for more self-hosted setups.
For the broader architecture—image boundaries, model caches, readiness, resource limits, and agent isolation—read Docker for AI development.
Why Run Ollama in Docker?
Installing Ollama directly on your machine works fine for personal use. Docker solves the problems that show up everywhere else:
- Reproducibility — pinning an image makes the runtime easier to reproduce. Drivers, model versions and available memory still affect behavior and performance.
- Team sharing — spin up a shared Ollama instance on a team server. Everyone hits the same API endpoint without installing anything locally.
- Server deployment — deploy to any cloud VM, on-prem server, or Kubernetes cluster with a single
docker compose up. - Isolation — keep Ollama and its dependencies contained. No conflicts with other software on the host.
- Easy upgrades — pull a new image tag and restart. Rolling back is just as simple.
If you’re deploying Ollama for anything beyond personal tinkering, Docker is the way to go.
Prerequisites
You need two things installed on your host machine:
Docker Engine (v20.10+) or Docker Desktop:
# Verify Docker is installed
docker --version
docker compose version
NVIDIA Container Toolkit (required only for GPU passthrough):
For NVIDIA GPU acceleration, install the NVIDIA Container Toolkit. Model size alone does not determine whether CPU inference is acceptable: memory, quantization and latency requirements also matter. We cover the installation in the GPU passthrough section below.
For CPU-only usage, Docker alone is sufficient.
Quick Start with Docker Run
The fastest way to get Ollama running in a container:
docker run -d \
--name ollama \
-p 127.0.0.1:11434:11434 \
-v ollama_data:/root/.ollama \
ollama/ollama
This does three things:
- Publishes the Ollama API on the host’s loopback address, port
11434 - Creates a named volume
ollama_dataso downloaded models persist across container restarts - Runs in detached mode
Pull and run a model:
docker exec ollama ollama pull llama3.1
docker exec ollama ollama run llama3.1 "Explain Docker in one sentence"
Hit the API from your host:
curl http://localhost:11434/api/generate -d '{
"model": "llama3.1",
"prompt": "What is Docker?",
"stream": false
}'
This works, but Docker Compose gives you more control.
Docker Compose with GPU and Persistent Storage
Create a docker-compose.yml as a single-host starting point. Authentication, backups, resource limits and monitoring require separate decisions:
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama_data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
environment:
- OLLAMA_HOST=0.0.0.0
volumes:
ollama_data:
Start it:
docker compose up -d
Key details:
deploy.resources.reservations.devices— passes all NVIDIA GPUs to the container. Changecount: alltocount: 1if you want to limit it.ollama_datavolume — models are stored in/root/.ollamainside the container. The named volume ensures they survive container recreation.OLLAMA_HOST=0.0.0.0— listens on interfaces inside the container. The separate host port mapping restricts host access to loopback; this setting does not supply authentication.restart: unless-stopped— the container comes back up after reboots automatically.
For CPU-only usage, remove the entire deploy block.
Docker Compose with Open WebUI (Full Stack)
For a complete local AI setup with a ChatGPT-style interface, combine Ollama with Open WebUI:
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama_data:/root/.ollama
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
restart: unless-stopped
environment:
- OLLAMA_HOST=0.0.0.0
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
ports:
- "127.0.0.1:3000:8080"
volumes:
- openwebui_data:/app/backend/data
environment:
- OLLAMA_BASE_URL=http://ollama:11434
depends_on:
- ollama
restart: unless-stopped
volumes:
ollama_data:
openwebui_data:
docker compose up -d
Open http://localhost:3000 in your browser. Create an account (stored locally), pull a model through the UI or via CLI, and start chatting. The OLLAMA_BASE_URL environment variable tells Open WebUI where to find the Ollama API — Docker’s internal DNS resolves the ollama service name automatically.
These examples intentionally serve the host machine, not a public team endpoint. Remote team access needs an authenticated access layer and TLS; do not remove the loopback restriction merely to make a connection work. See our full Open WebUI guide for authentication and model management.
How to Access the Ollama Docker API
The correct API address depends on where the client runs:
| Client location | Address | Why |
|---|---|---|
| Host terminal | http://localhost:11434 | Uses the published loopback port |
| Another service in this Compose project | http://ollama:11434 | Docker DNS resolves the service name |
| Another computer | Not exposed by these examples | Add controlled remote access rather than publishing an unauthenticated API |
Check connectivity before asking a model to generate:
curl http://localhost:11434/api/tags
docker logs ollama
The tags response lists downloaded models; an empty list means the API is reachable but you still need to pull a model. Inside a client container, localhost refers to that client, not the Ollama service. Use http://ollama:11434 on the shared network. Connection refused is a network/service problem; a model-not-found response calls for checking the model name or download instead.
Ollama’s local API does not require authentication. Docker publishing without an explicit host address normally binds on all host interfaces, so the loopback mapping is deliberate. It is not a substitute for securing Docker networks and the host itself. These are configuration examples, not a claim of a tested production deployment.
Sources: Ollama Docker documentation, local API authentication, list models API, and Docker port publishing, checked September 30, 2026.
GPU Passthrough Setup
Docker doesn’t see your GPU by default. The NVIDIA Container Toolkit bridges that gap.
Step 1 — Install NVIDIA drivers on the host:
# Verify your GPU is detected
nvidia-smi
If this command doesn’t work, install the appropriate NVIDIA drivers for your distribution first.
Step 2 — Install the NVIDIA Container Toolkit:
# Add the repository
curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | \
sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg
curl -s -L 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
Step 3 — Configure Docker to use the NVIDIA runtime:
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
Step 4 — Verify GPU access inside a container:
docker run --rm --gpus all nvidia/cuda:12.4.0-base-ubuntu22.04 nvidia-smi
You should see your GPU listed. If this works, the deploy.resources block in the Compose files above will function correctly.
For AMD GPUs, check the Ollama Docker documentation for the ROCm image and required device mappings; NVIDIA settings are not interchangeable with AMD settings.
Common Issues
Models disappear after restarting the container
You’re not using a persistent volume. Make sure you have -v ollama_data:/root/.ollama in your run command or the volumes section in Compose.
“could not select device driver” error The NVIDIA Container Toolkit isn’t installed or configured. Run through the GPU passthrough setup steps above.
Container can’t access GPU but nvidia-smi works on host
Restart Docker after installing the toolkit: sudo systemctl restart docker. If using Docker Desktop, restart the application entirely.
Open WebUI shows “Ollama connection failed”
Check that OLLAMA_BASE_URL is set to http://ollama:11434 (the service name, not localhost). Both containers must be on the same Docker network, which Compose handles automatically.
Slow model loading First loads are slow because the model weights are read from disk into memory (or VRAM). Subsequent requests are fast. Use a volume backed by SSD storage for best performance.
Port 11434 already in use
A native Ollama service or another container may already own the port. Confirm which process it is before stopping it, or use 127.0.0.1:11435:11434 and call http://localhost:11435 from the host.
What’s Next
You now have Ollama running in Docker with GPU acceleration and optional web UI. From here you can:
- Scale with multiple model instances behind a load balancer
- Add authentication with a reverse proxy like Traefik or Caddy
- Integrate with your applications via the REST API on port 11434
- Explore vLLM for higher-throughput serving if you need production-grade inference
FAQ
Can Ollama run in Docker?
Yes, Ollama has an official Docker image (ollama/ollama) that works out of the box. You can run it with a single docker run command and access the API on port 11434, just like a native installation.
Does Docker Ollama support GPU?
Yes, Docker Ollama supports NVIDIA GPU passthrough via the NVIDIA Container Toolkit. Once the toolkit is installed and configured, you add a deploy.resources.reservations.devices block to your Compose file or use --gpus all with docker run.
How do I persist models in Docker?
Mount a named volume or bind mount to /root/.ollama inside the container. This ensures downloaded models survive container restarts and recreations — without it, you’d re-download models every time the container is removed.
Can I use Docker Compose with Ollama?
Yes. Compose defines GPU passthrough, persistent volumes, environment variables and multi-service stacks in one file. A Compose file alone does not provide production security or availability.
Related Guides
- Best Self-Hosted AI Models 2026 — which models to run locally
- Self-Hosted AI for Enterprise — scaling local AI across your organization