How to persist Ollama data in Docker
Ollama running in Docker container
What this does
Maps the container's model storage directory to a host filesystem path so models, history, and configuration survive container restarts and rebuilds. After this guide the Ollama data directory is backed by a persistent volume.
Steps
Identify the default models directory inside the container. Ollama stores models at
/root/.ollama/modelsby default.docker exec ollama ls /root/.ollama/modelsExpected output: Directory listing showing downloaded model folders.
Create the host directory for persistence.
mkdir -p ~/ollama-dataExpected output: Quiet success.
Stop and remove the existing container.
docker stop ollama && docker rm ollamaExpected output: Container ID printed for both commands.
Launch Ollama with a bind mount for the models directory.
docker run -d \ --name ollama \ -p 11434:11434 \ -v ~/ollama-data:/root/.ollama/models \ ollama/ollamaExpected output: Full container ID string.
Store the Docker Compose manifest for repeatability.
services: ollama: image: ollama/ollama:latest container_name: ollama ports: - "11434:11434" volumes: - ~/ollama-data:/root/.ollama/models restart: unless-stoppeddocker compose up -d
Verification
docker exec ollama ls /root/.ollama/models
# Expected: Directory listing identical to the host ~/ollama-data contents
Common failures
Error: no such container: ollama— The container was not namedollamawhen created. Find the name withdocker ps -a.- Models not found after recreate — The host path was empty at first run. Always stop the container before removing it.
- Permission denied — Run
chmod -R 755 ~/ollama-dataor adjust ownership. - Container exits immediately — The bind mount syntax is incorrect. Use an absolute path.
- Port already allocated — Port conflict with another process. Change the host port to
11435:11434. - Volume mount not propagating — On macOS Docker Desktop, file changes may be delayed. Use
docker restart ollamato force re-mount.