DockerCompose私有化部署Ollama方案

Posted :

in :

by :

services:
  ollama:
    image: ollama/ollama:latest
    ports:
      - 11434:11434
    volumes:
      - ./code:/code
      - ./ollama/ollama:/root/.ollama
    container_name: ollama
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all  # 分配所有可用 GPU
              capabilities: [gpu]
    environment:
      - OLLAMA_CONTEXT_LENGTH=32768  # 设置上下文长度为 32k
      - OLLAMA_NUM_GPU=0          # 0 表示使用所有可用 GPU
      - OLLAMA_KEEP_ALIVE=24h     # 模型保持活跃时间,减少冷启动
      - OLLAMA_HOST=0.0.0.0       # 允许外部访问
      - OLLAMA_ORIGINS=*          # 允许所有来源(根据需要调整安全性)
      - OLLAMA_DEBUG=0            # 启用调试日志
    pull_policy: always
    tty: true
    restart: always
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:11434/api/health"]
      interval: 30s
      timeout: 5s
      retries: 3
    logging:
      driver: "json-file"
      options:
        max-size: "10m"           # 日志文件大小限制
        max-file: "3"             # 最大日志文件数量
    networks:
      - ollama-docker

  open-webui:
    image: ghcr.io/open-webui/open-webui:main
    container_name: open-webui
    pull_policy: always
    volumes:
      - ./ollama/open-webui:/app/backend/data
    depends_on:
      - ollama
    ports:
      - 8080:8080
    environment:
      - '/ollama/api=http://ollama:11434/api'
    extra_hosts:
      - host.docker.internal:host-gateway
    restart: unless-stopped
    networks:
      - ollama-docker

networks:
  ollama-docker:
    external: false

Comments

发表回复