# Ollama + Open WebUI - Production Docker Compose
# Source: localaiops.com
#
# Usage:
#   docker compose up -d
#
# Requirements:
#   - Docker Engine 24.0+ with Compose v2
#   - NVIDIA Container Toolkit (for GPU support)
#   - At least 8GB RAM (16GB+ recommended for 7B+ models)
#
# After starting:
#   - Open WebUI: http://localhost:3000
#   - Ollama API: http://localhost:11434
#   - Pull a model: docker exec ollama ollama pull llama3.1:8b

services:
  ollama:
    image: ollama/ollama:latest
    container_name: ollama
    restart: unless-stopped
    ports:
      - "11434:11434"
    volumes:
      - ollama_data:/root/.ollama
    # Uncomment the deploy section below for GPU support
    # deploy:
    #   resources:
    #     reservations:
    #       devices:
    #         - driver: nvidia
    #           count: all
    #           capabilities: [gpu]
    environment:
      # Max concurrent requests (default: 1, increase for multi-user)
      - OLLAMA_NUM_PARALLEL=2
      # Bind to all interfaces (required for container networking)
      - OLLAMA_HOST=0.0.0.0
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:11434/api/tags"]
      interval: 30s
      timeout: 10s
      retries: 3

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    restart: unless-stopped
    ports:
      - "3000:8080"
    volumes:
      - openwebui_data:/app/backend/data
    environment:
      - OLLAMA_BASE_URL=http://ollama:11434
      # Disable telemetry
      - SCARF_NO_ANALYTICS=true
      - DO_NOT_TRACK=true
      # Optional: set a default model
      # - DEFAULT_MODELS=llama3.1:8b
    depends_on:
      ollama:
        condition: service_healthy

volumes:
  ollama_data:
    name: ollama_data
  openwebui_data:
    name: openwebui_data
