ai-dock ComfyUI

repository·main·Indexed 21 days ago

https://github.com/ai-dock/comfyui

A cloud-first Docker image for running ComfyUI on NVIDIA CUDA, AMD ROCm, or CPU platforms. It includes pre-configured Micromamba environments for ComfyUI and an API wrapper, support for hardware acceleration, and extensive configuration options via environment variables for authentication, model downloads (HuggingFace, Civitai), and service management.

Tokens
1.5K
Snippets
3
Records
10
Agent score
27%

What's inside ai-dock/comfyui

  1. Select and use the appropriate ComfyUI Docker image tag

    main

    AI-Dock provides ComfyUI images for different hardware backends. Choose a tag based on your target platform: NVIDIA CUDA, AMD ROCm, or CPU.

    Tag patterns:

    • CUDA: :cuda-[x.x.x-base|runtime]-[ubuntu-version]
    • ROCm: :rocm-[x.x.x-runtime]-[ubuntu-version]
    • CPU: :cpu-[ubuntu-version]

    The :latest tag points to :latest-cuda and represents a stable, tested version.

  2. Configure ComfyUI via environment variables

    main

    You can customize the ComfyUI container behavior using several environment variables. Note that these images do not bundle models; use a provisioning script to download them.

    VariableDescription
    AUTO_UPDATEUpdate ComfyUI on startup (default false)
    CIVITAI_TOKENAuthenticate download requests from Civitai (required for gated models)
    COMFYUI_ARGSStartup arguments (e.g., --gpu-only --highvram)
    COMFYUI_PORT_HOSTComfyUI interface port (default 8188)
    COMFYUI_REFGit reference for auto update (branch, tag, or commit hash). Default: latest release
    COMFYUI_URLOverride $DIRECT_ADDRESS:port with a specific URL
    HF_TOKENAuthenticate download requests from HuggingFace (required for gated models like SD3, FLUX, etc.)
  3. Configure GPU support for NVIDIA and AMD

    main

    To enable hardware acceleration, you must configure the docker-compose.yaml file based on your GPU type.

    NVIDIA GPUs

    Uncomment the deploy section in docker-compose.yaml to allow the container to access all available NVIDIA GPUs:

    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: all
              capabilities: [gpu]

    AMD GPUs

    For AMD hardware, ensure the device mapping for /dev/kfd is enabled in the devices section:

    devices:
      - "/dev/dri:/dev/dri"
      - "/dev/kfd:/dev/kfd"
  4. Use the ComfyUI API Wrapper

    main

    The ComfyUI API Wrapper is a service available on port 8188. It is intended to replace older serverless handlers.

    • Direct API Access: /ai-dock/api/
    • Swagger/OpenAPI Documentation: /ai-dock/api/docs

    Note: All services are password protected by default.

  5. Configure build variables via .env

    main

    The ComfyUI Docker image can be customized during the build process using environment variables in a .env file. These variables control the Python version, PyTorch version, and the base image used for the build.

    Available build arguments:

    • PYTHON_VERSION: The Python version to use (defaults to 3.10).
    • PYTORCH_VERSION: The PyTorch version to use (defaults to 2.4.1).
    • COMFYUI_BUILD_REF: Specific build reference for ComfyUI.
    • IMAGE_BASE: The base image URL (defaults to ghcr.io/ai-dock/python:${PYTHON_VERSION}-v2-cuda-12.1.1-base-22.04).
    • IMAGE_TAG: The tag for the resulting image.
    # Example .env content
    PYTHON_VERSION=3.10
    PYTORCH_VERSION=2.4.1
    IMAGE_TAG=custom-tag
  6. Configure workspace and storage volumes

    main

    The project uses a workspace volume to persist data. By default, the local ./workspace directory is mapped to the container's ${WORKSPACE} (defaulting to /workspace/).

    To share storage with other non-ComfyUI containers, you can map a common storage path to the /workspace/storage/ subdirectory within the container:

    volumes:
      - ./workspace:${WORKSPACE:-/workspace/}:rshared
      - /path/to/common_storage:${WORKSPACE:-/workspace/}storage/:rshared
  7. Access Python environments for ComfyUI and API

    main

    The image includes pre-configured Micromamba environments. The comfyui environment is activated automatically upon shell login.

    • comfyui: Contains ComfyUI and its dependencies.
    • api: Contains the ComfyUI API wrapper and its dependencies.
  8. Manage the ComfyUI service

    main

    ComfyUI runs as a service on port 8188 (unless COMFYUI_PORT_HOST is set). You can pass startup flags via the COMFYUI_ARGS environment variable.

    Use supervisorctl to manage the service lifecycle:

    # Examples of service management
    supervisorctl start comfyui
    supervisorctl stop comfyui
    supervisorctl restart comfyui
  9. Configure network ports and service access

    main

    The following environment variables control the host-side ports for various services. Use these to avoid conflicts with existing services on your machine:

    ServiceHost Port Env VarDefaultDescription
    SSHSSH_PORT_HOST2222SSH access (mapped to container port 22)
    Service PortalSERVICEPORTAL_PORT_HOST1111Caddy service portal
    ComfyUICOMFYUI_PORT_HOST8188ComfyUI web interface
    JupyterJUPYTER_PORT_HOST8888Jupyter server
    Syncthing UISYNCTHING_UI_PORT_HOST8384Syncthing web interface
    Syncthing TransportSYNCTHING_TRANSPORT_PORT_HOST22999Syncthing data transport
  10. Configure ComfyUI and Service environment variables

    main

    Use the following environment variables to configure the behavior of the ComfyUI container:

    Authentication and Security

    • WEB_ENABLE_AUTH: Enables/disables web authentication (default: true).
    • WEB_ENABLE_HTTPS: Enables/disables HTTPS (default: false).
    • WEB_USER: Username for web authentication (default: user).
    • WEB_PASSWORD: Password for web authentication (default: password).
    • CIVITAI_TOKEN: Token for Civitai integration.
    • HF_TOKEN: Hugging Face token for model downloads.

    Service Configuration

    • COMFYUI_ARGS: Additional command-line arguments passed to ComfyUI.
    • COMFYUI_URL: The URL for the ComfyUI service.
    • COMFYUI_METRICS_PORT: Port for ComfyUI metrics (default: 28188).
    • AUTO_UPDATE: Whether to enable auto-updates (default: false).
    • WORKSPACE: The path inside the container for the workspace (default: /workspace).
    • CF_TUNNEL_TOKEN: Cloudflare Tunnel token.
    • CF_QUICK_TUNNELS: Enable Cloudflare Quick Tunnels (default: true).