version: "3.9"

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    deploy:
      resources:
        reservations:
          devices:
            - capabilities: [gpu]
    environment:
      - OLLAMA_VULKAN=false
      - NVIDIA_VISIBLE_DEVICES=all
      - NVIDIA_DRIVER_CAPABILITIES=compute,utility
    volumes:
      - ollama:/root/.ollama
    ports:
      - "11434:11434"
    restart: unless-stopped
    entrypoint: >
      sh -c "
      ollama serve &
      sleep 3 &&
      ollama pull llama3:latest &&
      ollama pull mistral:latest &&
      ollama pull phi3:mini &&
      wait
      "

volumes:
  ollama:
