### Example Pre-Init Script Execution Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Demonstrates a simple shell script placed in the pre-init directory to install an extra Python package before ComfyUI initialization. ```bash # Example pre-init script: docker/scripts/pre-init/01-configure-pip.sh #!/bin/bash pip install --quiet some-extra-package==1.2.3 echo "Extra package installed." ``` -------------------------------- ### Example Post-Init Script for Notifications Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt A Python script for the post-init directory that sends a webhook notification to confirm ComfyUI is ready to start. ```python # Example post-init script: docker/scripts/post-init/99-notify.py import subprocess # Send a webhook notification once ComfyUI is about to start subprocess.run([ "curl", "-s", "-X", "POST", "https://hooks.example.com/comfyui-ready", "-d", '{"text": "ComfyUI is starting!"}', ]) ``` -------------------------------- ### Copy Example Environment File Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md Create a .env file for your configuration by copying the example file. Refer to example.env for detailed options. ```bash cp example.env .env ``` -------------------------------- ### Start ComfyUI with Docker Compose Source: https://github.com/jimlee2048/comfyui-docker/blob/main/AGENTS.md Boots ComfyUI using the sample compose setup in the docker/ directory. Use -d for detached mode and 'docker compose down' to stop. ```bash cd docker && docker compose up ``` -------------------------------- ### Copy Example Docker Compose File Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md Create your docker-compose.yml file by copying the example configuration. See docker/compose.example.yml for more details. ```bash cp compose.example.yml compose.yml ``` -------------------------------- ### ComfyUI Docker Boot Configuration Example Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt This TOML file defines custom nodes for ComfyUI Docker. It specifies the repository URL and the branch to use for installation. ```toml # docker/config/01-nodes.toml [[custom_nodes]] repo = "https://github.com/comfyanonymous/ComfyUI_experiments.git" branch = "main" ``` -------------------------------- ### ComfyUI Docker Compose Setup Example Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt This YAML configuration defines a ComfyUI Docker service, including image, container name, environment file, port mapping, volume mounts for persistence, and GPU resource allocation. ```yaml # docker/compose.yml services: comfyui-docker: image: jimlee2048/comfyui-docker:latest # or :nightly, :vX.Y.Z container_name: comfyui-docker env_file: .env ports: - 8188:8188 volumes: # Persisted ComfyUI user data (workflows, settings, logs) - ./volumes/user:/workspace/ComfyUI/user # Generated output images - ./volumes/output:/workspace/ComfyUI/output # Model files — largest volume, persisted across image updates - ./volumes/models:/workspace/ComfyUI/models # Boot config TOML files (optional if INIT_NODE & INIT_MODEL are false) - ./config:/workspace/boot_config # Pre/post hook scripts (optional) - ./scripts:/workspace/scripts # Mount an external custom node directory for development (optional) # - /path/to/my_node:/workspace/ComfyUI/custom_nodes/my_node security_opt: - "label=type:nvidia_container_t" deploy: resources: reservations: devices: - driver: nvidia device_ids: ["0"] # GPU index capabilities: [gpu] ``` -------------------------------- ### ComfyUI Docker Environment Variables Example Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt This example demonstrates a full set of environment variables for configuring ComfyUI Docker, including node and model initialization, exclusion patterns, API tokens, and network settings. ```bash # docker/.env — full working example INIT_NODE=true UPDATE_NODE=false INIT_MODEL=true # Exclude config files whose path contains "example" or "debug" BOOT_CONFIG_EXCLUDE=(?:example|debug) # Extra ComfyUI launch flags COMFYUI_EXTRA_ARGS="--preview-method=auto --disable-auto-launch" # API tokens for gated models HF_API_TOKEN=hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx CIVITAI_API_TOKEN=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx # Enable Chinese mainland mirrors (hf-mirror.com, civitai.work, ustc pip) CN_NETWORK=false LOG_LEVEL=INFO ``` -------------------------------- ### Install Python Dependencies with uv sync Source: https://github.com/jimlee2048/comfyui-docker/blob/main/AGENTS.md Installs Python dependencies from uv.lock. Run this command at the repository root before modifying the src/ directory. ```bash uv sync ``` -------------------------------- ### Install Custom Nodes from Comfy Registry or Git Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Configuration for installing custom nodes, either by specifying a node ID and version from the Comfy Registry or by providing a Git repository URL and branch. ```toml [[custom_nodes]] node_id = "comfyui-impact-pack" version = "latest" # "latest" | "nightly" | "v1.2.3" [[custom_nodes]] node_id = "comfyui-controlnet-aux" version = "nightly" [[custom_nodes]] url = "https://github.com/ltdrdata/ComfyUI-Impact-Pack" branch = "main" # optional — pin a branch/tag script = "post-install-impact-pack.sh" # optional post-install hook in scripts/post-install-node/ ``` -------------------------------- ### Launch ComfyUI with Docker Compose Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md Start ComfyUI using Docker Compose. Use 'docker compose up' for foreground logging (recommended for initial runs) or 'docker compose up -d' to run in the background. ```bash docker compose up ``` ```bash docker compose up -d ``` -------------------------------- ### ComfyUI Docker Initial Run and Management Commands Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt These bash commands cover the initial setup, running, restarting, and updating of the ComfyUI Docker container using Docker Compose. ```bash # First run (foreground, see all logs) cd comfyui-docker/docker cp compose.example.yml compose.yml cp example.env .env docker compose up # Background docker compose up -d # Restart to apply config/env changes docker compose down && docker compose up -d # Pull latest image and restart docker compose pull && docker compose down && docker compose up -d # Access ComfyUI open http://localhost:8188 ``` -------------------------------- ### Clone ComfyUI Docker Repository Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md Clone the repository and navigate to the docker directory to begin setup. ```bash git clone https://github.com/jimlee2048/comfyui-docker cd comfyui-docker/docker ``` -------------------------------- ### Log Progress with Context Manager Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Use the `Progress` context manager to prepend `[current/total]` counters to log lines within its scope. This is useful for providing clear progress feedback during batched operations like installations or downloads. ```python from comfyui_helper.utils import Progress import logging logger = logging.getLogger(__name__) items = ["model_a.safetensors", "model_b.safetensors", "model_c.safetensors"] with Progress(total_steps=len(items)) as p: for item in items: p.advance() logger.info(f"Processing {item}...") # Logs: [1/3] Processing model_a.safetensors... # [2/3] Processing model_b.safetensors... # [3/3] Processing model_c.safetensors... ``` -------------------------------- ### ComfyUI Docker CLI Invocation Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt The equivalent command-line interface invocation for starting ComfyUI within the Docker environment. This is typically used internally by the Docker image. ```bash # Equivalent CLI invocation (used inside the Docker image) comfyui-boot ``` -------------------------------- ### Install, Remove, and Update Custom Nodes with NodesManager Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt NodesManager computes the diff between current and previous states to manage custom nodes, installing new ones and removing stale ones. Nodes can be from Comfy Registry or Git. ```python from comfyui_helper.nodes import NodesManager current_config = [ {"node_id": "comfyui-impact-pack", "version": "latest"}, {"url": "https://github.com/cubiq/ComfyUI_IPAdapter_plus", "branch": "main"}, ] prev_state = [ # Previously installed node that is no longer in config → will be removed {"name": "comfyui-old-node", "source": "registry", "version": "nightly"}, ] manager = NodesManager(current_config=current_config, prev_state=prev_state) result = manager.init_nodes() if result is None: print("No config changes — nothing to do.") else: installed, removed, existed, failed = result print(f"Installed: {len(installed)}, Removed: {len(removed)}, " f"Existed: {len(existed)}, Failed: {len(failed)}") # Installed: 2, Removed: 1, Existed: 0, Failed: 0 # Update all nodes in config (calls cm-cli update on each) updated, failed = manager.update_nodes() # Bulk update ALL installed nodes (equivalent to cm-cli update all) NodesManager.update_all_nodes() ``` -------------------------------- ### Manage Custom Nodes with Node Class Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Use the Node class to manage custom nodes from registries or Git repositories. It supports installation, removal, updates, and checking existence and exclusion status. ```python from comfyui_helper.nodes import Node # Registry node node = Node(name="comfyui-impact-pack", source="registry", version="latest") print(node) print(node.is_exists()) # Git node with pinned branch and post-install script git_node = Node( name="comfyui-ipadapter-plus", source="git", url="https://github.com/cubiq/ComfyUI_IPAdapter_plus", version="main", script="post-install-ipadapter.sh", ) # Install (skips if already present; True=installed, None=existed, False=failed) result = git_node.install(setup_exists=False) # Remove (True=removed, None=not found, False=error) result = git_node.remove() # Update via cm-cli git_node.update() # Check exclusion (comfyui-manager is excluded by default) print(node.is_excluded()) ``` -------------------------------- ### Initialize and Run ComfyUILauncher Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Instantiate ComfyUILauncher to manage the full boot sequence, including config loading, script execution, and ComfyUI process management. The startup() method runs the entire boot process. ```python from pathlib import Path from comfyui_helper.boot import ComfyUILauncher launcher = ComfyUILauncher( app_path=Path("/workspace/ComfyUI"), config_dir=Path("/workspace/boot_config"), state_path=Path("/workspace/prev-state.json"), include_config=None, exclude_config=r"(?:example|debug)", pre_init_scripts=Path("/workspace/scripts/pre-init"), post_init_scripts=Path("/workspace/scripts/post-init"), update_nodes=False, # UPDATE_NODE env init_nodes=True, # INIT_NODE env init_models=True, # INIT_MODEL env listen="0.0.0.0,::", port=8188, extra_args="--preview-method=auto --disable-auto-launch", ) # Runs the full boot sequence: # 1. Load config + previous state # 2. Execute pre-init scripts # 3. (Optional) update_all_nodes via cm-cli # 4. Install/remove custom nodes # 5. Download/remove/move models # 6. Execute post-init scripts # 7. Print init summary # 8. Launch: python /workspace/ComfyUI/main.py --listen 0.0.0.0,:: --port 8188 ... # 9. Forward SIGTERM/SIGINT for clean shutdown launcher.startup() # Process stays alive until ComfyUI exits; sys.exit(exit_code) is called on exit. ``` -------------------------------- ### Run ComfyUI Helper Entry Point Locally Source: https://github.com/jimlee2048/comfyui-docker/blob/main/AGENTS.md Exercises the helper entry point locally to quickly check config parsing. This is the fastest regression test. ```bash uv run comfyui-boot --help ``` -------------------------------- ### Download Models from Hugging Face or Civitai Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Configuration for downloading models, specifying the URL for Hugging Face or Civitai, and the target directory and filename for saving. ```toml # docker/config/02-models.toml ## Download from Hugging Face (HF_API_TOKEN used automatically if set) [[models]] url = "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors" dir = "models/checkpoints/sdxl" filename = "sd_xl_base_1.0.safetensors" [[models]] url = "https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors" dir = "models/vae/sdxl" filename = "sdxl_vae_fp16_fix.safetensors" ## Download from Civitai (CIVITAI_API_TOKEN appended as query param automatically) [[models]] url = "https://civitai.com/api/download/models/30163?type=Model&format=SafeTensor&size=full&fp=fp16" dir = "models/checkpoints/sd15" filename = "AnythingV5_v5PrtRE.safetensors" ``` -------------------------------- ### Persist and Compare Boot State with StateManager Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt StateManager loads the previous boot state from a JSON file, holds the current state, and writes it back. The delta between previous and current state drives install/remove/move decisions. ```python from pathlib import Path from comfyui_helper.boot import StateManager state_path = Path("/workspace/prev-state.json") sm = StateManager(store_path=state_path) # Read previous state (empty dict on first run) print(sm.prev_state) # {"custom_nodes": [...], "models": [...]} or {} # After nodes are processed, persist the successfully handled nodes sm.update("custom_nodes", [node_obj1, node_obj2]) # After models are processed sm.update("models", [model_obj1]) # Manually write state (called automatically by update()) sm.write() # Writes JSON to /workspace/prev-state.json: # { # "custom_nodes": [{"name": "comfyui-impact-pack", "source": "registry", ...}], # "models": [{"url": "https://...", "filename": "sd_xl_base_1.0.safetensors", "dir": "models/checkpoints/sdxl", ...}] # } ``` -------------------------------- ### Configure Automatic Node/Model Management Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md Enable automatic node and model management by setting INIT_NODE or INIT_MODEL to true in your .env file. Custom configurations can be placed in docker/config/. ```bash # Set INIT_NODE=true or/and INIT_MODEL=true in docker/.env ``` -------------------------------- ### Build ComfyUI Docker Image Source: https://github.com/jimlee2048/comfyui-docker/blob/main/AGENTS.md Rebuilds the full Docker image with your changes. Use the -f flag to specify the Dockerfile. ```bash docker build -f Dockerfile.cuda -t comfyui-docker:dev . ``` -------------------------------- ### Execute Scripts in a Directory Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Utility function to find, sort, and execute all supported scripts within a specified directory. It returns a status indicating success, partial failure, or full failure. ```python from pathlib import Path from comfyui_helper.utils import exec_scripts_in_dir # Returns True if all scripts succeeded (or no scripts found), # False if all failed, True with warnings if partial failure result = exec_scripts_in_dir(Path("/workspace/scripts/pre-init")) # Logs: # 🛠️ Found 2 scripts in pre-init: # └─ 01-configure-pip.sh # └─ 02-setup-env.py # ✅ All 2 scripts in pre-init succeeded. ``` -------------------------------- ### Manage Single Model File with Model Class Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt The Model class represents a single model file, handling its filesystem path, cache cleanup, download, and removal. It requires a Downloader instance for file transfers. ```python from comfyui_helper.models import Model from comfyui_helper.download import Downloader model = Model( url="https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors", dir="models/vae/sdxl", filename="sdxl_vae_fp16_fix.safetensors", ) print(model) print(model.path) print(model.is_exists()) # Download (requires a running aria2c — handled automatically by Downloader) downloader = Downloader() result = model.download(downloader) # Remove result = model.remove() ``` -------------------------------- ### Load and Merge TOML Config Files with ConfigManager Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt Use ConfigManager to load TOML files from a directory, filter them using regex patterns, sort by numeric prefix, and merge custom nodes and models configurations. ```python from pathlib import Path from comfyui_helper.config import ConfigManager # Load all .toml files from ./config/, excluding any file whose path matches "example" cm = ConfigManager( config_dir=Path("/workspace/boot_config"), include_pattern=None, exclude_pattern=r"(?:example|debug)", ) config = cm.config # config == { # "custom_nodes": [{"node_id": "comfyui-impact-pack", "version": "latest"}, ...], # "models": [{"url": "https://...", "dir": "models/checkpoints/sdxl", "filename": "..."}, ...], # } nodes_cfg = config.get("custom_nodes", []) models_cfg = config.get("models", []) print(f"Nodes: {len(nodes_cfg)}, Models: {len(models_cfg)}") # Filter to only a specific config set at runtime cm_filtered = ConfigManager( config_dir=Path("/workspace/boot_config"), include_pattern=r"01-base", # only load files matching "01-base" ) ``` -------------------------------- ### Run Pytest for Testing Source: https://github.com/jimlee2048/comfyui-docker/blob/main/AGENTS.md Runs tests using pytest in quiet mode. Aim to cover all modified modules and add regression cases for bug fixes. ```bash uv run pytest -q ``` -------------------------------- ### Filter Path List with Regex Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt A utility function for filtering lists of Path objects using include and exclude regular expression patterns. Useful for managing configuration files. ```python from pathlib import Path from comfyui_helper.utils import filter_path_list paths = [ Path("/workspace/boot_config/01-base.toml"), Path("/workspace/boot_config/02-extras.toml"), Path("/workspace/boot_config/example.toml"), Path("/workspace/boot_config/debug-nodes.toml"), ] # Exclude files whose path contains "example" or "debug" filtered = filter_path_list(paths, exclude_pattern=r"(?:example|debug)") # [Path('.../01-base.toml'), Path('.../02-extras.toml')] # Include only files whose path contains "extras" filtered = filter_path_list(paths, include_pattern=r"extras") # [Path('.../02-extras.toml')] # Combined include + exclude filtered = filter_path_list( paths, include_pattern=r"\d+-", # must have numeric prefix exclude_pattern=r"debug", ) # [Path('.../01-base.toml'), Path('.../02-extras.toml')] ``` -------------------------------- ### Restart Docker Container for Configuration Changes Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md When modifying boot config or environment variables, do not use ComfyUI Manager's restart function. Instead, restart the container to apply changes. ```bash docker compose down docker compose up -d ``` -------------------------------- ### Download Files with Downloader Class (aria2c) Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt The Downloader class provides a robust file download mechanism using aria2c. It supports basic downloads, authenticated downloads with custom headers, and configurable retry logic. ```python from comfyui_helper.download import Downloader dl = Downloader() # Basic download success = dl.download( url="https://huggingface.co/some-org/some-repo/resolve/main/model.safetensors", filename="model.safetensors", dir="/workspace/ComfyUI/models/checkpoints", ) # With Authorization header (e.g. for gated HuggingFace repos) success = dl.download( url="https://huggingface.co/meta-llama/Llama-2-7b/resolve/main/model.safetensors", filename="llama2-7b.safetensors", dir="/workspace/ComfyUI/models/checkpoints", header="Authorization: Bearer hf_xxxxxxxxxxxxxxxxxxxx", max_retries=5, retries_interval=3, ) ``` -------------------------------- ### Manage Model Files with ModelsManager Source: https://context7.com/jimlee2048/comfyui-docker/llms.txt The ModelsManager class processes model configurations to determine download, remove, and move queues based on state differences. It utilizes the Downloader for file transfers and automatically injects API tokens. ```python from comfyui_helper.models import ModelsManager current_config = [ { "url": "https://huggingface.co/stabilityai/stable-diffusion-xl-base-1.0/resolve/main/sd_xl_base_1.0.safetensors", "dir": "models/checkpoints/sdxl", "filename": "sd_xl_base_1.0.safetensors", }, { "url": "https://civitai.com/api/download/models/30163?type=Model&format=SafeTensor", "dir": "models/checkpoints/sd15", "filename": "AnythingV5_v5PrtRE.safetensors", }, ] prev_state = [] manager = ModelsManager(current_config=current_config, prev_state=prev_state) result = manager.init_models() if result is None: print("No model config changes.") else: downloaded, removed, moved, existed, failed = result print(f"Downloaded: {len(downloaded)}, Removed: {len(removed)}, " f"Moved: {len(moved)}, Existed: {len(existed)}, Failed: {len(failed)}") # Downloaded: 2, Removed: 0, Moved: 0, Existed: 0, Failed: 0 ``` -------------------------------- ### Stop ComfyUI Docker Services Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md To stop the running ComfyUI services, use the 'docker compose down' command. ```bash docker compose down ``` -------------------------------- ### Update ComfyUI Docker Image Source: https://github.com/jimlee2048/comfyui-docker/blob/main/README.md To update the ComfyUI Docker image, pull the latest image and then restart the container. This ensures you are running the most recent version. ```bash docker compose pull docker compose down docker compose up -d ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.