Deploying LLMs With Docker: A Practical Container Guide
Deploying LLMs with Docker starts with Ollama's official image, a named volume, and a GPU flag. Covers setup, Compose files, and production checks.
By Galactic News Editorial · Published 2026-11-16T22:44:14+00:00 · Updated 2026-11-16T22:44:14+00:00
Deploying LLMs With Docker: A Practical Container Guide
Deploying LLMs with Docker means packaging the model server, its dependencies, and its API into one portable container. The most common route is Ollama's official image. One command starts a local model server. A named volume keeps the models. A GPU flag adds acceleration. This guide walks through the full setup, from CPU-only to production.
Containers solve the classic LLM deployment problem. A model that works on a laptop breaks on a server because a library version differs. Docker freezes the environment. The same image runs on a laptop, a workstation, and a cloud VM. That consistency is the whole point.
Deploying LLMs with Docker: the Ollama quick start
Ollama publishes an official image as ollama/ollama on Docker Hub. The CPU-only start is one line:
docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollamaThree flags do the work. The -v ollama:/root/.ollama flag creates a named volume for the model store. Without it, every pulled model dies with the container. The -p 11434:11434 flag publishes the API port. The -d flag runs the container in the background.
Then pull a model and test it:
docker exec -it ollama ollama pull llama3.2
docker exec -it ollama ollama run llama3.2
curl http://localhost:11434/api/versionThe image's entrypoint is /bin/ollama serve, so the container is the server. You talk to it with docker exec or over HTTP on port 11434. The image sets OLLAMA_HOST=0.0.0.0:11434 inside the container. For a dev box, bind the port to localhost only with -p 127.0.0.1:11434:11434. Never publish the API to the open internet without authentication in front of it.
Adding a GPU: NVIDIA and AMD
A container cannot see a GPU unless the host hands one over. Ollama does not error when the hand-over is missing. It just runs slowly on the CPU. That silent fallback is the most common Docker LLM mistake. Always verify the GPU is visible after starting the container.
For NVIDIA cards on Linux, install the NVIDIA Container Toolkit on the host first. Register it with Docker, restart the Docker daemon, then add --gpus=all:
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker
docker run -d --gpus=all -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollamaVerify with docker exec -it ollama nvidia-smi. If that command fails, the toolkit is not wired up. Check the driver with nvidia-smi on the host first, then the toolkit install.
For AMD cards, use the ROCm tag and pass the two device nodes:
docker run -d --device /dev/kfd --device /dev/dri -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama:rocmOn macOS, Docker Desktop cannot pass the GPU through. Run Ollama as a native app instead. Containerized Ollama on a Mac runs on CPU only.
A Docker Compose file you can keep in your repo
A Compose file turns the run command into versioned config. This CPU baseline works on any host:
services:
ollama:
image: ollama/ollama
container_name: ollama
restart: unless-stopped
ports:
- "127.0.0.1:11434:11434"
volumes:
- ollama:/root/.ollama
environment:
- OLLAMA_KEEP_ALIVE=5m
volumes:
ollama:Start it with docker compose up -d. The OLLAMA_KEEP_ALIVE variable controls how long a loaded model stays in memory after the last request. Five minutes is a good default for a dev server. Set it to zero to unload models immediately, or to a longer value on a busy server.
For NVIDIA GPUs, add a device reservation under deploy.resources. That is the Compose equivalent of --gpus=all. Keep the volume and the localhost port binding the same. One file then covers CPU and GPU hosts with a single changed block.
Add a chat UI as a second service when the team needs one. Open WebUI connects to Ollama over the shared internal network at http://ollama:11434. The service name is the hostname. Publish the UI port, not the Ollama port, to the outside world.
Choosing a serving engine: Ollama vs vLLM
| Factor | Ollama | vLLM |
|---|---|---|
| Best for | Local dev, small teams, single-server use | High-throughput production serving |
| Setup | One official image, one command | More config, GPU-focused |
| API | Native API plus OpenAI-compatible endpoints | OpenAI-compatible API server |
| GPU | Optional; CPU fallback is silent | GPU required for real workloads |
| Model format | GGUF models from its library | Hugging Face models, safetensors |
Ollama wins on simplicity. One image, one volume, and the model library handles downloads. vLLM wins on throughput. Its paged attention engine serves many concurrent requests on one GPU. For a team API behind a product, vLLM is the stronger choice. For a dev server or an internal tool, Ollama is enough.
Other engines exist for specific needs. Text generation inference and llama.cpp cover niche cases. Start with Ollama, measure the load, and move to vLLM when latency or concurrency demands it. Changing engines later is easier than overbuilding now.
Production checklist: security, updates, and monitoring
Work through this checklist before the container goes live. First, bind the API to localhost or put a reverse proxy with authentication in front of it. Ollama has no built-in auth. An open port 11434 is an open model server for anyone who finds it.
Second, pin the image tag. Use ollama/ollama:0.40.2 instead of latest. The latest tag moves on every release. A pinned tag makes rollbacks possible and deployments repeatable.
Third, set resource limits. Ollama sizes its thread pool from the host core count and ignores a Compose cpus: limit, according to a community report. Set memory limits in Compose and watch actual usage. A model that exceeds RAM will be killed without warning.
Fourth, back up the volume. The named volume holds every pulled model. A deleted volume means re-downloading gigabytes. Snapshot it with the rest of the server backup. Keep the model list in a script so a rebuild is one command.
Fifth, monitor the basics. Check container health with docker ps. Watch GPU use with nvidia-smi. Log API errors from the app that calls the model, not from Ollama alone. Set an alert for container restarts. A container that restarts often has a memory problem.
Sixth, plan updates. Pull the new image, stop the old container, and start a new one on the same volume. Models survive because they live in the volume, not the container. Test the new version with one request before routing traffic to it.
Bottom line
Start with the official Ollama image, a named volume, and a localhost port binding. Add the GPU only after verifying it is visible inside the container. Keep the setup in a Compose file with a pinned tag. Put authentication in front of the API before it goes live. That is a complete, production-ready LLM deployment in one container.