services:
comfyui:
build:
context: .
dockerfile: Dockerfile.comfyui
args:
- USER_ID=${USER_ID:-1000}
- GROUP_ID=${GROUP_ID:-1000}
# container_name: comfyui-flux # keep ONLY if external tooling depends on a fixed name
user: "${USER_ID:-1000}:${GROUP_ID:-1000}"
restart: unless-stopped
command: [
"--listen", "0.0.0.0",
"--port", "8188",
"--highvram", # Keep models loaded when active
"--disable-metadata", # Don't save metadata in images
"--cache-lru", "3", # Small LRU cache for aggressive eviction
# "--disable-smart-memory", # REMOVED: Would use too much system RAM
"--fp8_e4m3fn-text-enc", # FP8 text encoder (saves ~2.4GB)
"--reserve-vram", "1.0" # Reserve 1GB for OS/system safety (reduced for limited RAM)
]
init: true
shm_size: "16g"
ports:
- "${PORT:-8188}:8188"
env_file:
- .env
secrets:
- hf_token
volumes:
# Model directories - persistent storage
- ./models:/app/ComfyUI/models
- ./output:/app/ComfyUI/output
- ./input:/app/ComfyUI/input
- ./custom_nodes:/app/ComfyUI/custom_nodes
# Cache for model downloads
- comfyui-cache:/root/.cache
environment:
- NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES:-all}
- CUDA_VISIBLE_DEVICES=${CUDA_VISIBLE_DEVICES:-0}
- PYTORCH_CUDA_ALLOC_CONF=${PYTORCH_CUDA_ALLOC_CONF:-max_split_size_mb:512}
- MODEL_PRECISION=${MODEL_PRECISION:-fp16}
- TORCH_CUDNN_V8_API_LRU_CACHE_LIMIT=${TORCH_CUDNN_V8_API_LRU_CACHE_LIMIT:-32}
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
networks:
- mcp-network
healthcheck:
test: ["CMD-SHELL", "curl -sf http://localhost:8188/system_stats >/dev/null"]
interval: 15s
timeout: 5s
retries: 10
start_period: 40s
logging:
options:
max-size: "10m"
max-file: "3"
mcp-server:
build:
context: .
dockerfile: Dockerfile.mcp
# container_name: mcp-comfyui-server # see note above re: multiple stacks
restart: unless-stopped
init: true
env_file:
- .env
secrets:
- anthropic_api_key
- mcp_auth_token
volumes:
- ./src:/app/src:ro
- ./output:/app/output
- ./package.json:/app/package.json:ro
- ./package-lock.json:/app/package-lock.json:ro
- claude-config:/root/.config/claude
- claude-cache:/root/.cache
environment:
- COMFYUI_HOST=comfyui
- COMFYUI_PORT=8188
- NODE_ENV=${NODE_ENV:-production}
- CLAUDE_CODE_DISABLE_TELEMETRY=1
- DISABLE_AUTOUPDATER=1
- ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY:-}
depends_on:
comfyui:
condition: service_healthy
networks:
- mcp-network
stdin_open: true
tty: true
read_only: true
tmpfs:
- /tmp
security_opt:
- no-new-privileges:true
healthcheck:
test: ["CMD-SHELL", "curl -sf http://comfyui:8188/system_stats >/dev/null"]
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
logging:
options:
max-size: "10m"
max-file: "3"
networks:
mcp-network:
driver: bridge
volumes:
comfyui-cache:
claude-config:
claude-cache:
# Docker secrets configuration
secrets:
anthropic_api_key:
file: ./secrets/anthropic_api_key.txt
hf_token:
file: ./secrets/hf_token.txt
mcp_auth_token:
file: ./secrets/mcp_auth_token.txt