Overview
Introduction
Running Ollama locally is usually one `docker run` command, until you want persistent model storage, GPU acceleration, and a reproducible setup you can check into a repo, at which point a docker-compose.yml is the better fit.
This tool generates that compose file: the official image, the exposed API port, a persistent named volume, an optional GPU reservation, and a reminder of the pull command to run once the container is up.
What Is Ollama Docker Compose Generator?
A generator for a single-service docker-compose.yml running `ollama/ollama:latest`, with port 11434 mapped, a named volume mounted at /root/.ollama for model persistence, and an OLLAMA_HOST environment variable.
It optionally adds a `deploy.resources.reservations.devices` block requesting an NVIDIA GPU, matching the configuration the NVIDIA Container Toolkit expects for GPU-accelerated inference.
How Ollama Docker Compose Generator Works
You name the cache volume, set the OLLAMA_HOST value, toggle GPU reservation, and specify which model you plan to pull. The generator validates the volume name and required fields, then assembles a valid compose file.
The GPU toggle inserts a `deploy.resources.reservations.devices` entry with `driver: nvidia`, `count: all`, and `capabilities: [gpu]`, the standard shape Docker Compose uses to hand a container access to the host's GPU(s) via the NVIDIA Container Toolkit.
When To Use Ollama Docker Compose Generator
Use it when standing up a local or self-hosted Ollama instance for development, testing a RAG pipeline, or serving models to other containers on the same Docker network.
It's also useful when you need GPU acceleration and don't want to hand-write the NVIDIA reservation block from memory each time.
Often used alongside Hugging Face Config Generator, OpenAI Environment Generator and LangChain Config Generator.
Features
Advantages
- Persists downloaded models in a named volume so they survive container recreation and image upgrades.
- Includes the exact `docker compose exec ollama ollama pull <model>` command you need to run after startup, rather than leaving you to guess it.
- GPU support is a single toggle away, using the standard Compose device-reservation shape rather than a bespoke script.
Limitations
- GPU acceleration additionally requires the NVIDIA Container Toolkit installed on the host; the compose file alone doesn't install it.
- Only configures a single Ollama service; multi-model routing, load balancing across replicas, or a reverse proxy in front of it are out of scope.
Examples
Best Practices & Notes
Best Practices
- Pull the model once after the first `docker compose up -d`, since the volume persists it for subsequent restarts without re-downloading.
- Keep OLLAMA_HOST bound to 0.0.0.0 inside the container and control external exposure through the Docker port mapping or a reverse proxy, rather than trying to restrict it from inside the container.
- Size the host's disk for the models you plan to run; a 70B-parameter model can require tens of gigabytes in the volume.
Developer Notes
The GPU reservation follows the Compose Specification's `deploy.resources.reservations.devices` schema (`driver: nvidia`, `capabilities: [gpu]`), which `docker compose up` only honors when the NVIDIA Container Toolkit's runtime is registered with the Docker daemon; without it, Compose will start the container without GPU access rather than failing outright on most setups.
Ollama Docker Compose Generator Use Cases
- Standing up a local Ollama server for development against a RAG or agent pipeline
- Serving a self-hosted model to other containers on the same Docker Compose network
- Reproducing a GPU-accelerated Ollama setup consistently across machines via a checked-in compose file
Common Mistakes
- Enabling the GPU block without having the NVIDIA Container Toolkit installed, then being confused why inference still runs on CPU.
- Forgetting to pull a model after the first startup and then getting a 404 from the API when trying to generate against it.
Tips
- Add this service into a larger docker-compose.yml alongside your app container and reference it by service name, e.g. http://ollama:11434, over the shared Compose network instead of localhost.