Autor: Jakub Rusinowski · Ostatnia aktualizacja: 21 lipca 2026
Running Ollama in Docker gives you reproducible, isolated, easy-to-update AI infrastructure. This guide covers everything from a single-server setup to a multi-GPU deployment with a load balancer.
Running Ollama in Docker gives you reproducible, isolated, easy-to-update AI infrastructure. This guide covers everything from a single-server setup to a multi-GPU deployment with a load balancer.
docker pull updates Ollama without uninstalling# Ubuntu/Debian
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 | 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
docker run -d \
--gpus all \
-v ollama:/root/.ollama \
-p 11434:11434 \
--name ollama \
--restart unless-stopped \
ollama/ollama
The -v ollama:/root/.ollama mounts a named volume so model files persist across container restarts.
# Pull a model
docker exec -it ollama ollama pull llama3.1:8b
# List available models
docker exec -it ollama ollama list
# Run a test prompt
docker exec -it ollama ollama run llama3.1:8b "What is VRAM?"
Create a full AI stack with Ollama + Open WebUI:
version: "3.8"
services:
ollama:
image: ollama/ollama:latest
container_name: ollama
restart: unless-stopped
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
volumes:
- ollama_data:/root/.ollama
ports:
- "11434:11434"
environment:
- OLLAMA_NUM_PARALLEL=4 # Allow 4 concurrent requests
- OLLAMA_MAX_LOADED_MODELS=2 # Keep 2 models in VRAM simultaneously
- OLLAMA_KEEP_ALIVE=24h # Keep models loaded for 24 hours
open-webui:
image: ghcr.io/open-webui/open-webui:main
container_name: open-webui
restart: unless-stopped
ports:
- "3000:8080"
volumes:
- webui_data:/app/backend/data
environment:
- OLLAMA_BASE_URL=http://ollama:11434
depends_on:
- ollama
volumes:
ollama_data:
webui_data:
Start everything:
docker-compose up -d
| Variable | Default | Description |
|---|---|---|
| OLLAMA_NUM_PARALLEL | 1 | Concurrent inference requests |
| OLLAMA_MAX_LOADED_MODELS | 1 | Models kept in VRAM at once |
| OLLAMA_KEEP_ALIVE | 5m | How long to keep a model in VRAM after use |
| OLLAMA_MAX_QUEUE | 512 | Max queued requests before rejecting |
| OLLAMA_NUM_GPU | all | Number of GPUs to use |
For multiple GPUs, Ollama automatically uses all available GPUs for a single model via tensor parallelism:
docker run -d --gpus all \
-e OLLAMA_NUM_GPU=2 \
-v ollama:/root/.ollama \
-p 11434:11434 \
ollama/ollama
With dual RTX 4090s (48 GB combined VRAM), you can run Llama 3.3 70B Q4 at ~55 tokens/second.
# Check if Ollama is healthy
curl http://localhost:11434/api/health
# Monitor GPU usage
watch -n1 nvidia-smi
# View container logs
docker logs -f ollama
# Check API response
curl http://localhost:11434/api/tags
nginx.conf for reverse proxy with basic auth:
server {
listen 443 ssl;
server_name your-ai.example.com;
ssl_certificate /etc/letsencrypt/live/your-ai.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/your-ai.example.com/privkey.pem;
location / {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
proxy_pass http://localhost:11434;
proxy_set_header Host $host;
proxy_read_timeout 600s;
}
}
docker pull ollama/ollama:latest
docker-compose down
docker-compose up -d
Model files in the ollama_data volume are preserved — no need to re-pull models.