HOW-TO · SET

How to persist Ollama data in Docker

intermediate10 minBy Fredoline Eruo
Target environment
Ubuntu 24.04 · Ollama 0.4.xWindows 11 · Ollama 0.4.xmacOS 15 · Ollama 0.4.x
PREREQUISITES

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

  1. Identify the default models directory inside the container. Ollama stores models at /root/.ollama/models by default.

    docker exec ollama ls /root/.ollama/models
    

    Expected output: Directory listing showing downloaded model folders.

  2. Create the host directory for persistence.

    mkdir -p ~/ollama-data
    

    Expected output: Quiet success.

  3. Stop and remove the existing container.

    docker stop ollama && docker rm ollama
    

    Expected output: Container ID printed for both commands.

  4. 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/ollama
    

    Expected output: Full container ID string.

  5. 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-stopped
    
    docker 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 named ollama when created. Find the name with docker 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-data or 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 ollama to force re-mount.

Related guides

RELATED GUIDES