Docker runs a program inside a container: a sealed box that carries everything the program needs and runs the same way on any machine with Docker. Ollama publishes an official image, ollama/ollama, and its Docker page covers CPU-only runs, Nvidia GPUs with the NVIDIA Container Toolkit, AMD GPUs with the rocm tag, and Vulkan support. Running Ollama this way keeps the server, its libraries and its models separate from the rest of your computer.
Start the container with a volume for models
The one detail that matters most is the volume. Models live under /root/.ollama inside the container, so without a volume they vanish when the container is removed. The command below starts the official image in the background, keeps models in a named volume called ollama, and publishes the API port on the loopback address only, so only your own computer can reach it:
docker run -d -v ollama:/root/.ollama -p 127.0.0.1:11434:11434 --name ollama ollama/ollama
For an Nvidia GPU, Ollama’s Docker page says to install the NVIDIA Container Toolkit first, then add --gpus=all to the same command. For an AMD GPU, the page says to use the rocm tag instead: ollama/ollama:rocm.
Pull and run a model inside the container
The Ollama command line is part of the same image, so run it with docker exec against the running container:
docker exec -it ollama ollama pull llama3.2docker exec -it ollama ollama run llama3.2
The first command downloads the model into the volume; the second opens a chat with it. From your own computer you can also use the API exactly as with a normal install, because the port is published on localhost:11434.
Try it: three checks that the container works
| Check | Command | What you should see |
|---|---|---|
| Container is running | docker ps --filter name=ollama |
The ollama container listed as running |
| Server answers | curl http://localhost:11434 |
“Ollama is running” |
| Model is stored | docker exec ollama ollama list |
llama3.2 in the list of models |
Expected result. We checked Ollama’s Docker page and the Continue guide’s Ollama check. We did not run Docker or pull a model on this machine.
Limits
Without the -v ollama:/root/.ollama volume, removing the container deletes every downloaded model with it, so treat the volume as part of the setup, not an optional extra. The image listens on every network address inside the container, so publishing the port without the 127.0.0.1: prefix would open your models to the whole network; the command above binds it to your own computer only. A container also adds a layer between Ollama and your hardware, so on a laptop the native install is usually the simpler and faster choice. We did not test any of this ourselves.
