-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New ComfyUI Dockerfile features #739
base: master
Are you sure you want to change the base?
Conversation
Sorry to post asking for help here, but I can't get this to run due to some issue with your UID/GID changes. Any idea what's going on here? Do I have to configure my host system in a particular way?
ComfyUI and A1111 run fine using the base repo FWIW. |
Hi, this seems to be a great place for such issues. Testing is helpful. Based on your comment:
I presume that your volumes have been created using the base repo default of UID/GID 0:0 or the root user. This is expected behavior since the UID has changed. The most "secure" option is to change the ownership of the existing files. I ran a command like this (only a single execution should be required): podman run --rm -u root -v sd-comfy-data:/data -v sd-comfy-output:/output -it localhost/sd-comfy:7 bash -c 'chown -R app:app /data /output' Perhaps something like: docker run --rm -u root -v <data volume name or path>:/data -v <output volume name or path>:/output -it localhost/sd-comfy:7 bash -c 'chown -R app:app /data /output' Alternatively, you could re-build the image to use the root UID by passing build arguments: While I'd explicitly avoided adding an automatic scripted action to enforce the recursive directory ownership, perhaps we can re-consider it if enough users require it. |
@lainedfles thanks for the quick response! As you can tell, I don't know what I'm doing with Docker, but I think I see what was going on. This is the command that worked for me (no "actual" docker volumes, just directories on host): docker run --rm -u root -v ./data:/data -v ./output:/output -it sd-comfy:7 bash -c 'chown -R app:app /data /output' It's running and generating images now, but I do get this CNAUX error upon server startup:
Here's my config, which I specified directly in the Dockerfile (hope that's not terribly bad practice). Intended use is with Krita + some SDXL checkpoints: ARG USE_UID=131
ARG USE_GID=131
ARG USE_EDGE=false
ARG USE_GGUF=false
ARG USE_XFLUX=false
ARG USE_CNAUX=true
ARG USE_KRITA=true
ARG USE_IPAPLUS=true
ARG USE_INPAINT=true
ARG USE_TOOLING=true |
Edit: this contains good troubleshooting information so I'll leave it but I think I've identified the issue. I'll add a new commit to the PR soon. @SummitCollie No prob! I've been playing around with Aider.
This is strange. Have you made any modifications aside from env arg defaults? I'd guess a few possible causes:
On my system, $ docker exec -it comfy-1 bash -c 'find / -iname libGL.so.1'
$ docker exec -it comfy-1 bash -c 'ls -lh /usr/lib/x86_64-linux-gnu/libGL.so.1'
You do you! It looks OK to me but FYI, enabling the single variable |
@lainedfles Ah that was my mistake, I ended up solving it about 1 minute before you responded 😿 I had commented out the second part of this line because the Ultimately I removed the -RUN apt-get update && apt-get install -y git && ([ "${USE_XFLUX}" = "true" ] && apt-get install -y libgl1-mesa-glx python3-opencv) && apt-get clean
+RUN apt-get update && apt-get install -y git libgl1-mesa-glx python3-opencv && apt-get clean |
@SummitCollie good work. I think that the new commit should provide a fix. Just tested Flux.1 Schnell (Have you tried the Flux.1 models? They're incredible!). Here's the result, cheers! |
@lainedfles Thanks again! Also btw, - if [ "${KRITA_DOWNLOAD_MODELS:-false}" = "true" ]; then
- cd "${ROOT}/krita-ai-diffusion/scripts" && python scripts/download_models.py --recommended /data && cd ..
+ if [ "${KRITA_DOWNLOAD_MODELS:-true}" = "true" ]; then
+ cd "${ROOT}/krita-ai-diffusion/scripts" && python download_models.py --recommended /data && cd .. I also changed the default from |
@SummitCollie Good catch! Thanks for the help testing this. I'll add a new commit tomorrow to fix that (unless you want to submit a PR to my branch). I'll also fire up my dusty Ubuntu VM tomorrow and try building this with docker compose. I suspect that you may be able to set the environment variables prepended to the command, something like |
This commit introduces the use of an `.env` file for environment variable management across all defined services in the `docker-compose.yml`. By adding `env_file: .env`, each service will now load environment variables from a local `.env` file, enhancing configuration flexibility and security. This change ensures that sensitive information or common settings can be centralized and easily managed without hardcoding them into the Docker Compose file.
This commit introduces a new `.env` file for environment variable management and updates the `.gitignore` file to ensure that this sensitive configuration file is not tracked by version control. This change helps maintain security by preventing accidental exposure of environment-specific settings in the repository.
This commit introduces several new model paths to the `extra_model_paths.yaml` file under the `a111` section. The added paths include `unet`, `clip_vision`, `xlabs`, `inpaint`, and `ipadapter`. These additions enhance the configuration by providing more options for different models, which can be utilized in various functionalities within the service.
… in entrypoint.sh This commit introduces several enhancements to the `entrypoint.sh` script for the Comfy service: 1. **Custom Node Management**: Added logic to update custom nodes located in `/data/config/comfy/custom_nodes/`. If the `UPDATE_CUSTOM_NODES` environment variable is set to `true`, it will pull the latest changes from each node's Git repository and update submodules recursively for specific nodes like `krita-ai-diffusion`. 2. **Environment Variable Usage**: Introduced a new environment variable `CACHE` which should be used instead of hardcoding `/root/.cache`. This makes the script more flexible and configurable. 3. **Krita Integration**: Added support for Krita integration with ComfyUI, including downloading models if `KRITA_DOWNLOAD_MODELS` is set to `true`, managing upscale models, and setting up symbolic links for model directories. 4. **GGUF, XFLUX, CNAUX, IPAPLUS, INPAINT, TOOLING Support**: Included logic to handle additional custom nodes (`ComfyUI-GGUF`, `x-flux-comfyui`, `comfyui_controlnet_aux`, `ComfyUI_IPAdapter_plus`, `comfyui-inpaint-nodes`, `comfyui-tooling-nodes`) based on their respective environment variables (`USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`). These nodes are moved to the custom nodes directory if they don't already exist. 5. **Model Management**: Added functionality to download and manage specific models required by certain integrations, such as CLIP Vision and IP Adapters for XFLUX. These changes enhance the script's flexibility, making it easier to integrate additional features and manage dependencies dynamically based on environment configurations.
…rations This commit significantly enhances the `Dockerfile` for the ComfyUI service by introducing several new features and configurations. Here's a detailed breakdown of the changes: 1. **Base Image Update**: - Updated the base image from `pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime` to `pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime`. This ensures compatibility with newer versions of PyTorch and CUDA, providing better performance and support for recent hardware. 2. **Environment Variables**: - Introduced several new environment variables (`USE_UID`, `USE_GID`, `USE_USER`, `USE_GROUP`) to allow customization of the user and group IDs within the container. - Added flags (`USE_EDGE`, `USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_KRITA`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`) to enable or disable optional features and integrations. 3. **User/Group Management**: - Added logic to create a user and group with specified IDs (`USE_UID` and `USE_GID`). This is useful for running the container in environments where specific user permissions are required. - Set default values for these variables, ensuring that the Dockerfile remains functional without explicit configuration. 4. **Optional Feature Integration**: - Included conditional logic to clone and install additional repositories based on the flags set (`USE_GGUF`, `USE_XFLUX`, `USE_CNAUX`, `USE_KRITA`, `USE_IPAPLUS`, `USE_INPAINT`, `USE_TOOLING`). This allows users to customize their ComfyUI installation by enabling only the features they need. - Ensured that dependencies for these optional features are installed correctly, including handling specific cases like separating ONNX Runtime installations to restore CUDA support. 5. **Python Version Update**: - Changed the Python command from `python` to `python3` in the CMD instruction to explicitly specify the use of Python 3, which is a best practice for clarity and compatibility. 6. **File Permissions and Ownership**: - Used `--chown=${USE_UID}:${USE_GID}` when copying files into the container to ensure that the correct user owns these files, preventing permission issues during execution. 7. **General Improvements**: - Improved readability and maintainability of the Dockerfile by organizing the steps logically and adding comments where necessary. - Ensured that all commands are idempotent, meaning they can be run multiple times without causing unintended side effects. - `USE_UID`: Specifies the user ID for the non-root user within the container. Default is set to value 0. - `USE_GID`: Specifies the group ID for the non-root user within the container. Default is set to value like 0. - `USE_USER`: Specifies the username for the non-root user within the container. Default is set to `root`. - `USE_GROUP`: Specifies the group name for the non-root user within the container. Default is set to `root`. - `USE_EDGE`: If set to `true`, clones and installs the latest development version of ComfyUI from the main branch. - `USE_GGUF`: If set to `true`, clones and installs the ComfyUI-GGUF extension for GPU acceleration. - `USE_XFLUX`: If set to `true`, clones and installs the x-flux-comfyui extension for additional functionalities. - `USE_CNAUX`: If set to `true`, clones and installs the comfyui_controlnet_aux extension for control net auxiliary features. - `USE_KRITA`: If set to `true`, clones and installs multiple extensions (comfyui_controlnet_aux, ComfyUI_IPAdapter_plus, comfyui-inpaint-nodes, comfyui-tooling-nodes) that are useful when integrating with Krita. - `USE_IPAPLUS`: If set to `true`, clones and installs the ComfyUI_IPAdapter_plus extension for IP Adapter functionalities. - `USE_INPAINT`: If set to `true`, clones and installs the comfyui-inpaint-nodes extension for inpainting capabilities. - `USE_TOOLING`: If set to `true`, clones and installs the comfyui-tooling-nodes extension for additional tooling features. These ARGs provide flexibility in configuring the Docker container, allowing users to tailor the ComfyUI installation to their specific needs.
aa03ba0
to
1ba0fa8
Compare
…int.sh This commit addresses an issue where the script did not change back to the original directory after creating a symbolic link. By adding `&& cd ..` at the end of the `ln -sfT /data/models/upscale_models upscale_models` command, we ensure that the working directory remains consistent and expected for subsequent operations in the script. This fix prevents potential errors or unexpected behavior due to an incorrect current working directory.
This commit refactors the `entrypoint.sh` script to enhance error handling and ensure consistent use of quotes around variables. Specifically: 1. **Error Handling**: Added `set +e` before `git pull` commands within the loop for updating custom nodes, allowing the script to continue processing other nodes even if one fails. This is followed by `set -e` to revert to strict error handling. 2. **Consistent Quoting**: Ensured that all variables are quoted consistently throughout the script to prevent issues with spaces or special characters in file paths. 3. **Command Placement**: Moved the model download command for Krita after checking and creating symbolic links, ensuring that models are downloaded into the correct directory structure. 4. **Use of `cp -a` Instead of `mv`**: Changed the use of `mv` to `cp -a` when copying custom nodes to preserve file attributes and avoid accidental deletion of source files. These changes improve the robustness and reliability of the script, making it more resilient to errors and ensuring that all operations are performed correctly.
This commit fixes an issue in the `entrypoint.sh` script where the directory was not being changed back to its original location after running the model download script for Krita. The `cd ..` command has been replaced with `cd -`, which correctly returns to the previous working directory, ensuring that subsequent commands in the script are executed from the expected path. This change prevents potential errors and ensures the script behaves as intended.
@SummitCollie I think this PR is ready. I've reverted the non-root default to better align with the presumed intent. Running as non-root now requires additional build arguments. If you try this, I'd appreciate if you'd comment about your experience. 👍🏻 |
@lainedfles Just wanted to say your changes are working great for me! Thank you so much for this effort!! |
@coopbri It's been a pleasure, thank you for the testing and feedback! |
Dockerfile overhaul
Enhance the
Dockerfile
for the ComfyUI service by introducing several new features and configurations. The ARGs provide flexibility in configuring the Docker container, allowing users to tailor the ComfyUI installation to their specific needs. Here's a detailed breakdown of the changes:Base Image Update:
pytorch/pytorch:2.3.0-cuda12.1-cudnn8-runtime
topytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
. This ensures compatibility with newer versions of PyTorch and CUDA, providing better performance and support for recent hardware.Environment Variables:
USE_UID
,USE_GID
,USE_USER
,USE_GROUP
) to allow customization of the user and group IDs within the container.USE_EDGE
,USE_GGUF
,USE_XFLUX
,USE_CNAUX
,USE_KRITA
,USE_IPAPLUS
,USE_INPAINT
,USE_TOOLING
) to enable or disable optional features and integrations.User/Group Management:
USE_UID
andUSE_GID
). This is useful for running the container in environments where specific user permissions are required.Optional Feature Integration:
USE_GGUF
,USE_XFLUX
,USE_CNAUX
,USE_KRITA
,USE_IPAPLUS
,USE_INPAINT
,USE_TOOLING
). This allows users to customize their ComfyUI installation by enabling only the features they need.Python Version Update:
python
topython3
in the CMD instruction to explicitly specify the use of Python 3, which is a best practice for clarity and compatibility.File Permissions and Ownership:
--chown=${USE_UID}:${USE_GID}
when copying files into the container to ensure that the correct user owns these files, preventing permission issues during execution.General Improvements:
USE_UID
: Specifies the user ID for the non-root user within the container. Default is set to value 0.USE_GID
: Specifies the group ID for the non-root user within the container. Default is set to value like 0.USE_USER
: Specifies the username for the non-root user within the container. Default is set toroot
.USE_GROUP
: Specifies the group name for the non-root user within the container. Default is set toroot
.USE_EDGE
: If set totrue
, clones and installs the latest development version of ComfyUI from the main branch.USE_GGUF
: If set totrue
, clones and installs the ComfyUI-GGUF extension for GPU acceleration.USE_XFLUX
: If set totrue
, clones and installs the x-flux-comfyui extension for additional functionalities.USE_CNAUX
: If set totrue
, clones and installs the comfyui_controlnet_aux extension for control net auxiliary features.USE_KRITA
: If set totrue
, clones and installs multiple extensions (comfyui_controlnet_aux, ComfyUI_IPAdapter_plus, comfyui-inpaint-nodes, comfyui-tooling-nodes) that are useful when integrating with Krita.USE_IPAPLUS
: If set totrue
, clones and installs the ComfyUI_IPAdapter_plus extension for IP Adapter functionalities.USE_INPAINT
: If set totrue
, clones and installs the comfyui-inpaint-nodes extension for inpainting capabilities.USE_TOOLING
: If set totrue
, clones and installs the comfyui-tooling-nodes extension for additional tooling features.New entrypoint.sh features
Introduce several enhancements to the
entrypoint.sh
script for the Comfy service. These changes enhance the script's flexibility, making it easier to integrate additional features and manage dependencies dynamically based on environment configurations:Custom Node Update: Added logic to update custom nodes located in
/data/config/comfy/custom_nodes/
. If theUPDATE_CUSTOM_NODES
environment variable is set totrue
, it will pull the latest changes from each node's Git repository.Environment Variable Usage: Introduced a new environment variable
CACHE
which should be used instead of hard-coding/root/.cache
. This makes the script more flexible and configurable.Krita Integration: Added support for Krita integration with ComfyUI, including downloading models if
KRITA_DOWNLOAD_MODELS
is set totrue
, managing upscale models, and setting up symbolic links for model directories.GGUF, XFLUX, CNAUX, IPAPLUS, INPAINT, TOOLING Support: Included logic to handle additional custom nodes (
ComfyUI-GGUF
,x-flux-comfyui
,comfyui_controlnet_aux
,ComfyUI_IPAdapter_plus
,comfyui-inpaint-nodes
,comfyui-tooling-nodes
) based on their respective environment variables (USE_GGUF
,USE_XFLUX
,USE_CNAUX
,USE_IPAPLUS
,USE_INPAINT
,USE_TOOLING
). These nodes are copied to the custom nodes directory if they don't already exist..env support
Add
.env
file support to docker-compose file for environment variable management across all defined services in thedocker-compose.yml
. By addingenv_file: .env
, each service will now load environment variables from a local.env
file, enhancing configuration flexibility and security. This change ensures that sensitive information or common settings can be centralized and easily managed without hard-coding them into the Docker Compose file.Examples
Podman
Build and run container with one line enabling bleeding edge ComfyUi, enable GGUF, XFLUX, and KRITA support (download recommended models):
Build a container suitable for use with a systemd service to run as non-root:
podman-compose --verbose --podman-build-args='--build-arg="USE_UID=991" --build-arg="USE_GID=991" --build-arg="USE_USER=app" --build-arg="USE_GROUP=app" --build-arg="USE_EDGE=true" --build-arg="USE_GGUF=true" --build-arg="USE_XFLUX=true" --build-arg="USE_KRITA=true"' --profile comfy build
Docker
Build to enable Krita support:
Use
.env
file to enable node updates and download recomended Krita models:Run container:
Closes issue #728
Edit: major refactor
Disclaimer: no code is AI generated (just old-fashioned human AGI) but various local LLMs were used to author commit messages.