version: '3.8' services: # ==================== API服务 ==================== api: build: context: . dockerfile: docker/APIDockerfile container_name: iopaint-api restart: unless-stopped ports: - "8080:8080" environment: # API配置 - API_KEY=${API_KEY:-change_me_in_production} - MAX_IMAGE_SIZE=${MAX_IMAGE_SIZE:-4096} - ENABLE_METRICS=true # 模型缓存(使用HuggingFace镜像加速下载) - HF_ENDPOINT=https://hf-mirror.com - HF_HOME=/root/.cache # PyTorch配置 - PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:512 volumes: # 模型缓存目录(避免每次重启重新下载模型) - ./models:/root/.cache:rw # 日志目录 - ./logs:/app/logs:rw deploy: resources: limits: cpus: '4' memory: 8G reservations: devices: - driver: nvidia count: 1 capabilities: [gpu] # 健康检查 healthcheck: test: ["CMD", "curl", "-f", "http://localhost:8080/api/v1/health"] interval: 30s timeout: 10s retries: 3 start_period: 60s # ==================== Nginx反向代理(可选)==================== nginx: image: nginx:alpine container_name: iopaint-nginx restart: unless-stopped ports: - "80:80" - "443:443" volumes: - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro - ./nginx/ssl:/etc/nginx/ssl:ro # SSL证书目录 - ./nginx/logs:/var/log/nginx:rw depends_on: - api profiles: - production # 使用 docker-compose --profile production up 启动 # ==================== 数据卷 ==================== volumes: models: driver: local logs: driver: local # ==================== 网络 ==================== networks: default: name: iopaint-network