# 非 host 版本, 容器内部使用桥接通信
# (各项参数均有详细的说明，理论情况下保持默认即可运行)
#version: '3'
services:
  comfyAI-web:
    container_name: comfyAI-web
    #更新修改冒号后面的版本号
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/one-ai:${VERSION}
    #端口冲突时，只需要修改前面的端口比如修改为，3011:3010
    labels:
      - "com.centurylinklabs.watchtower.enable=true"
    ports:
      - "${WEB_PORT}:3010"
    read_only: true
    networks:
      comfyai:
        ipv4_address: 172.21.0.8
    depends_on:
      - comfy-server
    restart: always
    environment:
      # 默认服务器地址，本地不需要更改，云服务需要修改为云端IP，并放行对应端口
      - NUXT_PUBLIC_BASE_APIURL=${NUXT_PUBLIC_BASE_APIURL}
      #增加服务端渲染配置，保持默认即可，不需要修改！
      - NUXT_PUBLIC_BASE_SSRURL=http://172.21.0.6:3001
      # 默认的服务器websocket地址，本地不需要更改，云服务需要修改为云端IP，并放行对应端口
      - NUXT_PUBLIC_BASE_SOCKETURL=${NUXT_PUBLIC_BASE_SOCKETURL}
    # 日志大小设置，避免日志文件过大
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "10"
    # 资源限制，防止内存溢出
    deploy:
      resources:
        limits:
          memory: 1500MB
        reservations:
          memory: 600MB
  comfy-server:
    container_name: comfy-server
    # 阿里云镜像地址
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/comfy-server:${VERSION} # 阿里云
    labels:
      - "com.centurylinklabs.watchtower.enable=true"
    ports:
      - "${SERVER_HTTP_PORT}:3001"    #http端口
      - "${SERVER_WS_PORT}:3002"    #websocket端口
#    read_only: true
    networks:
      comfyai:
        ipv4_address: 172.21.0.6
    depends_on:
      - mongo
      - redis
    restart: always
    environment:
      #  MongoDB配置，用户管理，不会配置的话保持默认即可
      - CONFIG_DB_MONGO_URI=mongodb://172.21.0.3:27017
      - CONFIG_DB_MONGO_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
      - CONFIG_DB_MONGO_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
      #  Redis配置，队列缓存，不会配置的话保持默认即可
      - CONFIG_COMFYUI_QUENE_REDIS_HOST=172.21.0.4
      - CONFIG_COMFYUI_QUENE_REDIS_PORT=6379
      - CONFIG_COMFYUI_QUENE_REDIS_PASSWORD=
      #日志与调试
      - LOG_LEVEL=${LOG_LEVEL}
      #Token过期时间，单位秒
      - CONFIG_TOKEN_EXPIRE=${CONFIG_TOKEN_EXPIRE}
      - CONFIG_JWT_SECRET=${CONFIG_JWT_SECRET}
      # 代理服务器
      - CONFIG_PROXY_URL=${CONFIG_PROXY_URL}
      #禁用文档 true/false/留空
      - CONFIG_DOCS_DISABLE=false
    # 日志大小设置，避免日志文件过大
    logging:
      driver: "json-file"
      options:
        max-size: "100m"
        max-file: "10"
  mongo:
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:latest
#    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/mongo-aliyun:4.4
    container_name: mongo
    restart: unless-stopped
    privileged: true
    # 生产环境建议不要暴露
    ports:
      - ${MONGO_PORT+${MONGO_PORT}:27017}
    networks:
      comfyai:
        ipv4_address: 172.21.0.3
    environment:
      # 这里的配置只有首次运行生效。修改后，重启镜像是不会生效的。需要把持久化数据删除再重启，才有效果
      - MONGO_INITDB_ROOT_USERNAME=${MONGO_INITDB_ROOT_USERNAME}
      - MONGO_INITDB_ROOT_PASSWORD=${MONGO_INITDB_ROOT_PASSWORD}
    volumes:
#      - /usr/local/mongo/data:/data/db
      - mongo_data:/data/db  # 使用docker volume存储数据，提高性能，避免兼容性问题
    healthcheck:
      test: ["CMD", "bash", "-c", "echo > /dev/tcp/localhost/${MONGO_PORT}"]
      interval: 30s
      retries: 3
      timeout: 10s
      start_period: 60s
  redis:
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/redis-aliyun:latest
    container_name: redis
    restart: always
    volumes:
      - ./redis.conf:/etc/redis/redis.conf  # 挂载本地 redis.conf
    command: [ "redis-server", "/etc/redis/redis.conf" ]  # 让 Redis 读取配置文件
#    ports:
#      - ${REDIS_PORT+${REDIS_PORT}:6379}
    read_only: true
    networks:
      comfyai:
        ipv4_address: 172.21.0.4
  watchtower:
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/watchtower-aliyun:latest
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --debug --http-api-update
    restart: always
    environment:
      - WATCHTOWER_HTTP_API_TOKEN=sk-ofJoA4atj9dki6AvDtI1qwxdcejjDQ
    labels:
      - "com.centurylinklabs.watchtower.enable=false"
#    ports:
#      - "${WATCHTOWER_PORT}:8080"
    read_only: true
    networks:
      comfyai:
        ipv4_address: 172.21.0.9
  portainer:
    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/portainer-ce:2.21.5
    container_name: portainer
    restart: always
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - portainer_data:/data
    networks:
      comfyai:
        ipv4_address: 172.21.0.11
#    ports:
#      - "${PORTAINER_PORT}:9000"
#      - "${PORTAINER_HTTPS_PORT}:9443"
    read_only: true
#  minio:
#    #    image: minio/minio
#    image: registry.cn-shanghai.aliyuncs.com/comfy-ai/minio:latest
#    ports:
#      - "9000:9000"
#      - "9001:9001" # MinIO Console (UI) 端口
#    volumes:
#      - ./data:/data # **修改这里：将 ./data 替换为你的本地路径**
#    environment:
#      MINIO_ROOT_USER: ${MINIO_ROOT_USER}
#      MINIO_ROOT_PASSWORD: ${MINIO_ROOT_PASSWORD} # 生产环境请务必修改
#    command: server /data --console-address ":9001"
#    healthcheck:
#      test: ["CMD", "curl", "-f", "http://localhost:9000/minio/health/live"]
#      interval: 30s
#      timeout: 20s
#      retries: 3
#    restart: always
volumes:
  mongo_data:
  portainer_data:
networks:
  comfyai:
    driver: bridge
    ipam:
      config:
        - subnet: 172.21.0.0/16
          gateway: 172.21.0.1


