Skip to content

Ollama Docker Compose

yaml
services:
  ollama:
    image: "ollama/ollama:latest"
    container_name: ollama
    ports:
      - "11434:11434"
    volumes:
      - "./model_files:/model_files"
      - "ollama:/root/.ollama"
    pull_policy: always
    tty: true
    restart: unless-stopped
    environment:
      - NVIDIA_VISIBLE_DEVICES=all
      - "NVIDIA_DRIVER_CAPABILITIES=compute,utility"
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
          count: 1
          capabilities:
            - gpu

  open-webui:
    image: "ghcr.io/open-webui/open-webui:main"
    container_name: open-webui
    ports:
      - "3000:8080"
    volumes:
      - "ollama-webui:/app/backend/data"
    depends_on:
      - ollama
    environment:
      - "OLLAMA_BASE_URL=http://ollama:11434"
    restart: unless-stopped
volumes:
  ollama:
    ollama-webui: null

run script

sh
#!/bin/bash

until curl -s http://localhost:11434/api/tags; do
  echo "waiting ollama..."
  sleep 2
  done

ollama create finetuned_mistral -f /model_files/Modelfile

Pull model

sh
docker exec -it ollama ollama pull llama3.2