diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..ac2a3a9d5 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +custom_nodes/* +models/* +output/* \ No newline at end of file diff --git a/.gitignore b/.gitignore index 61881b8a4..b83f95f26 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ venv/ *.log web_custom_versions/ .DS_Store +.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..30c1d2bb8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM python:3.12-slim +EXPOSE 8188 + +# Copy the repo and install required dependencies +WORKDIR /ComfyUI +COPY . . +RUN apt update && apt install git -y +RUN pip install --no-cache-dir -r requirements.txt + +# ComfyUI entrypoint +WORKDIR /ComfyUI +CMD [ "python", "main.py" ] \ No newline at end of file diff --git a/README.md b/README.md index f88d63f24..a5c1c41d5 100644 --- a/README.md +++ b/README.md @@ -44,14 +44,14 @@ This ui will let you design and execute advanced stable diffusion pipelines usin - [Mochi](https://comfyanonymous.github.io/ComfyUI_examples/mochi/) - Asynchronous Queue system - Many optimizations: Only re-executes the parts of the workflow that changes between executions. -- Smart memory management: can automatically run models on GPUs with as low as 1GB vram. +- Smart memory management: can automatically run models on GPUs with as low as 1GB of VRAM. - Works even if you don't have a GPU with: ```--cpu``` (slow) - Can load ckpt, safetensors and diffusers models/checkpoints. Standalone VAEs and CLIP models. - Embeddings/Textual inversion - [Loras (regular, locon and loha)](https://comfyanonymous.github.io/ComfyUI_examples/lora/) - [Hypernetworks](https://comfyanonymous.github.io/ComfyUI_examples/hypernetworks/) - Loading full workflows (with seeds) from generated PNG, WebP and FLAC files. -- Saving/Loading workflows as Json files. +- Saving/Loading workflows as JSON files. - Nodes interface can be used to create complex workflows like one for [Hires fix](https://comfyanonymous.github.io/ComfyUI_examples/2_pass_txt2img/) or much more advanced ones. - [Area Composition](https://comfyanonymous.github.io/ComfyUI_examples/area_composition/) - [Inpainting](https://comfyanonymous.github.io/ComfyUI_examples/inpaint/) with both regular and inpainting models. @@ -68,6 +68,7 @@ This ui will let you design and execute advanced stable diffusion pipelines usin - Starts up very fast. - Works fully offline: will never download anything. - [Config file](extra_model_paths.yaml.example) to set the search paths for models. +- [Docker](#running-with-docker) support Workflow examples can be found on the [Examples page](https://comfyanonymous.github.io/ComfyUI_examples/) @@ -213,6 +214,20 @@ For 6700, 6600 and maybe other RDNA2 or older: ```HSA_OVERRIDE_GFX_VERSION=10.3. For AMD 7600 and maybe other RDNA3 cards: ```HSA_OVERRIDE_GFX_VERSION=11.0.0 python main.py``` +# Running with Docker +Just execute the command below: + +```docker compose --profile up --build -d``` +## Profiles +```cpu``` - For CPU-only machines + +```cuda``` - For NVIDIA CUDA Chips + +## Additional variables for Docker (.env support) +```PORT``` - Port for ComfyUI + +```LISTEN_IP``` - IP address for ComfyUI to listen + ### AMD ROCm Tips You can enable experimental memory efficient attention on pytorch 2.5 in ComfyUI on RDNA3 and potentially other AMD GPUs using this command: @@ -304,4 +319,3 @@ This will use a snapshot of the legacy frontend preserved in the [ComfyUI Legacy ### Which GPU should I buy for this? [See this page for some recommendations](https://github.com/comfyanonymous/ComfyUI/wiki/Which-GPU-should-I-buy-for-ComfyUI) - diff --git a/compose.yml b/compose.yml new file mode 100644 index 000000000..8a4bfcaae --- /dev/null +++ b/compose.yml @@ -0,0 +1,33 @@ +# ComfyUI common x-variable +x-comfyui-common: &comfyui-common + build: + context: . + image: comfyui + ports: + - "${PORT:-8188}:8188" + volumes: + - "./custom_nodes:/ComfyUI/custom_nodes" + - "./models:/ComfyUI/models" + - "./output:/ComfyUI/output" + +# ComfyUI profiles +services: + comfyui-cpu: + <<: *comfyui-common + command: > + python main.py --listen=${LISTEN_IP:-0.0.0.0} --cpu + profiles: + - cpu + comfyui-cuda: + <<: *comfyui-common + command: > + python main.py --listen=${LISTEN_IP:-0.0.0.0} + profiles: + - cuda + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [ gpu ] \ No newline at end of file diff --git a/docker-run.bat b/docker-run.bat new file mode 100644 index 000000000..7fb01e67e --- /dev/null +++ b/docker-run.bat @@ -0,0 +1,43 @@ +@echo off + +:: Set default port and read from .env if exists +set "port=8188" +for /f "tokens=2 delims==" %%i in ('findstr /r "^PORT=" .env') do set "port=%%i" + +:: Check if NVIDIA GPU is available and set profile accordingly +for /f "tokens=*" %%i in ('wmic path win32_videocontroller get name ^| find /i "NVIDIA"') do set "profile=cuda" && goto pull +set "profile=cpu" + +:: Pull updates and handle local changes +:pull +set "cmdOutput=cmd_output.txt" +git pull > "%cmdOutput%" 2>&1 + +:: Handle potential conflicts or changes +findstr /C:"error: Your local changes to the following files would be overwritten by merge:" "%cmdOutput%" > nul && ( + echo Pull conflicts detected. Stashing changes... + git stash + git pull + goto rebuild +) + +findstr /C:"Already up to date." "%cmdOutput%" > nul || goto rebuild + +echo No changes detected. Starting Docker container... +docker compose --profile %profile% up -d +goto open_browser + +:: Rebuild section +:rebuild +echo Changes detected. Rebuilding Docker image... +docker compose --profile %profile% up --build -d + +:: Open the browser to localhost:%port% +:open_browser +echo Opening localhost:%port% in your default browser... +start http://localhost:%port% + +:: Cleanup section +:cleanup +del "%cmdOutput%" +exit /f 0 diff --git a/run.bat b/run.bat new file mode 100644 index 000000000..188c71d2c --- /dev/null +++ b/run.bat @@ -0,0 +1,41 @@ +@echo off + +:: Set default port and read from .env if exists +set "port=8188" +for /f "tokens=2 delims==" %%i in ('findstr /r "^PORT=" .env') do set "port=%%i" + +:: Set default venv path and read from .env if exists +set "venv_path=" +for /f "tokens=2 delims==" %%i in ('findstr /r "^VENV_PATH=" .env') do set "venv_path=%%i" + +:: Activate the virtual environment if specified +if not "%venv_path%"=="" ( + call "%venv_path%\Scripts\activate" + echo Activated virtual environment: %venv_path% +) else ( + echo No virtual environment specified. Using system Python. +) + +:: Pull updates and handle local changes +:pull +set "cmdOutput=cmd_output.txt" +git pull > "%cmdOutput%" 2>&1 + +:: Handle potential conflicts or changes +findstr /C:"error: Your local changes to the following files would be overwritten by merge:" "%cmdOutput%" > nul && ( + echo Pull conflicts detected. Stashing changes... + git stash + git pull +) + +findstr /C:"Already up to date." "%cmdOutput%" > nul || goto rebuild + +del "%cmdOutput%" + +echo No changes detected. Starting ComfyUI +pip install -r requirements.txt + +echo Opening localhost:%port% in your default browser... +start http://localhost:%port% + +python main.py