Skip to content

Commit cb32775

Browse files
Custom nodes are now installed on the host system
Previously, only the model files were stored outside of the container, but the custom nodes installed by ComfyUI Manager were not. The reason was that the ComfyUI Manager itself is implemented as a custom node, which means that mounting a host system directory into the custom nodes directory would hide the ComfyUI Manager. This problem was fixed by installing the ComfyUI Manager in a separate directory and symlinking it upon container startup into the mounted directory. Furthermore, the following changes were made: - Updated the image to the latest version of ComfyUI (from v0.3.4 to v0.3.7). - In the previous version, the main branch of the ComfyUI Manager was installed and not a specific version. Since the main branch may contain breaking changes or bugs, the ComfyUI Manager is now installed with a specific version (v2.55.5). - The ComfyUI Manager installs its dependencies when it is first launched. This means that the dependencies have to be installed every time the container is started. To avoid this, the dependencies are now installed manually during the image build process. - The directory structure of the ComfyUI models directory is now automatically created upon container startup if it does not exist. - The Docker image now has two more tags: one with the ComfyUI version and the second with the ComfyUI and ComfyUI Manager versions that are installed in the image. This makes it easier for users to find out which ComfyUI version they are installing before pulling the image. - A section was added to the read me, which explains how to update the local image to the latest version.
1 parent 833ac6a commit cb32775

File tree

6 files changed

+152
-26
lines changed

6 files changed

+152
-26
lines changed

.cspell.json

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
// Version of the settings file, this should always be 0.2
33
"version": "0.2",
44

5-
// The code in this repository is checked against British English, American English, and German
6-
"language": "en-gb,en-us,de-de",
5+
// The code in this repository is checked against British English and American English
6+
"language": "en-gb,en-us",
77

88
// A list of file types that should be enabled (not all file types are enabled by default)
99
"enableFiletypes": [
@@ -21,7 +21,7 @@
2121
"source/PersonalWebsite/Assets/libraries/**/*"
2222
],
2323

24-
// A list of dictionaries that should be added beyond the American English dictionary
24+
// A list of dictionaries that should be added beyond the British English and American English dictionaries
2525
"dictionaries": [
2626

2727
// Dictionaries that contain common misspellings
@@ -32,11 +32,8 @@
3232
// Dictionaries that contain the keywords of the programming, markup, styling, and configuration languages used in the project
3333
"docker",
3434

35-
// Other dictionaries, that contain the names of well-known companies, common acronyms related to computing, words used in data science,
36-
// common file extensions, common font names that may be used in CSS, common words often encountered in full-stack development, the
37-
// popular blind text Lorem Ipsum often used for testing text layout, terms common in computer networking, the most popular NPM packages that
38-
// may be used in Angular projects, terms used in popular public licenses, common software terms, and miscellaneous terms that are common in
39-
// software projects
35+
// Other dictionaries, that contain sub-specific words and names
36+
// projects
4037
"companies",
4138
"computing-acronyms",
4239
"data-science",
@@ -65,8 +62,17 @@
6562
// A list of words that are not in the included default dictionary for British English, American English, or German
6663
"words": [
6764
"comfyui",
65+
"controlnet",
6866
"cudnn",
67+
"findall",
68+
"gligen",
69+
"hypernetworks",
6970
"lecode",
71+
"loras",
72+
"photomaker",
73+
"PYTHONPATH",
74+
"pytorch",
75+
"unet",
7076
"vsicons"
7177
]
7278
}

.github/workflows/build-and-publish.yml

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ jobs:
4040
- name: Checkout repository
4141
uses: actions/checkout@v4
4242

43+
# Installs Python, which is used to extract the version of ComfyUI and the ComfyUI Manager from the Dockerfile using a regular expression
44+
- name: Install Python
45+
uses: actions/setup-python@v5
46+
with:
47+
python-version: '3.13'
48+
4349
# Logs in to the GitHub Container Registry registry using the account of the user that triggered the workflow run and the GitHub token that is
4450
# an automatically generated secret that is usually only used to access the repository (the permissions defined above allow the token to also
4551
# publish Docker images to the GitHub Container Registry) that will publish the packages. Once published, the packages are scoped to the account defined here.
@@ -50,21 +56,46 @@ jobs:
5056
username: ${{ github.actor }}
5157
password: ${{ secrets.GITHUB_TOKEN }}
5258

59+
# Extracts the versions of ComfyUI and the ComfyUI Manager from the Dockerfile using a Python script; the versions are written to the output
60+
# file, which are available in subsequent steps under steps.versions.outputs.COMFYUI_VERSION and steps.versions.outputs.COMFYUI_MANAGER_VERSION;
61+
# the versions are used to tag the Docker image, so that users know which versions of ComfyUI and the ComfyUI Manager are included in the image
62+
- name: Extract ComfyUI & ComfyUI Manager Versions
63+
id: versions
64+
shell: python
65+
run: |
66+
import os
67+
import re
68+
69+
def get_version(repository_name: str) -> str:
70+
with open('Dockerfile', mode='r', encoding='utf-8') as dockerfile:
71+
matches = re.findall(
72+
rf'git clone [a-zA-Z0-9:\/\.]+\/{repository_name}\.git[a-zA-Z0-9\-\/&\\\n ]+git checkout tags\/v?([0-9\.]+)',
73+
dockerfile.read(),
74+
re.MULTILINE
75+
)
76+
return matches[0] if matches else 'unknown'
77+
78+
with open(os.environ['GITHUB_OUTPUT'], mode='a', encoding='utf-8') as output_file:
79+
output_file.write(f'COMFYUI_VERSION={get_version('ComfyUI')}\n')
80+
output_file.write(f'COMFYUI_MANAGER_VERSION={get_version('ComfyUI-Manager')}\n')
81+
5382
# Extracts metadata from the Git repository and GitHub, which are then used to label and tag the Docker image that will be build in the next
5483
# step; the "id" property specifies that the output of this step will be available in subsequent steps under the name "metadata"; tags for the
5584
# SHA of the commit, the full semantic version extracted from the current tag (e.g., tag "v1.2.3" will be extracted as "1.2.3"), and the major
5685
# and minor version extracted from the current version (e.g., tag "v1.2.3" will be extracted as "1.2"), as well as a "latest" tag are added;
5786
# besides the hardcoded labels for the title and authors of the image, the GitHub description, GitHub license, GitHub revision, GitHub source
5887
# URL, GitHub URL, and creation date and time are extracted as labels
5988
- name: Extract Tags & Labels for Docker
60-
id: metadata
89+
id: docker-image-metadata
6190
uses: docker/metadata-action@v5
6291
with:
6392
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
6493
tags: |
6594
type=sha
66-
type=semver,pattern={{version}}
6795
type=semver,pattern={{major}}.{{minor}}
96+
type=semver,pattern={{version}}
97+
type=semver,pattern={{version}}-comfyui-${{ steps.versions.outputs.COMFYUI_VERSION }}
98+
type=semver,pattern={{version}}-comfyui-${{ steps.versions.outputs.COMFYUI_VERSION }}-comfyui-manager-${{ steps.versions.outputs.COMFYUI_MANAGER_VERSION }}
6899
labels: |
69100
org.opencontainers.image.title=ComfyUI Docker
70101
org.opencontainers.image.authors=David Neumann <david.neumann@lecode.de>
@@ -73,19 +104,19 @@ jobs:
73104
# the build context, which is the directory that contains the Dockerfile; the tags and labels extracted in the previous step are used to tag
74105
# and label the image
75106
- name: Build and Push Docker Image
76-
id: push
107+
id: build-and-push-docker-image
77108
uses: docker/build-push-action@v6
78109
with:
79110
context: .
80111
push: true
81-
tags: ${{ steps.metadata.outputs.tags }}
82-
labels: ${{ steps.metadata.outputs.labels }}
112+
tags: ${{ steps.docker-image-metadata.outputs.tags }}
113+
labels: ${{ steps.docker-image-metadata.outputs.labels }}
83114

84115
# Generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built; it increases supply chain
85116
# security for people who consume the image
86117
- name: Generate Artifact Attestation
87118
uses: actions/attest-build-provenance@v1
88119
with:
89120
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
90-
subject-digest: ${{ steps.push.outputs.digest }}
121+
subject-digest: ${{ steps.build-and-push-docker-image.outputs.digest }}
91122
push-to-registry: true

CHANGELOG.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Changelog
2+
3+
## v0.2.0 (December 16, 2024)
4+
5+
- Previously, only the model files were stored outside of the container, but the custom nodes installed by ComfyUI Manager were not. The reason was that the ComfyUI Manager itself is implemented as a custom node, which means that mounting a host system directory into the custom nodes directory would hide the ComfyUI Manager. This problem was fixed by installing the ComfyUI Manager in a separate directory and symlinking it upon container startup into the mounted directory.
6+
- Updated the image to the latest version of ComfyUI (from v0.3.4 to v0.3.7).
7+
- In the previous version, the main branch of the ComfyUI Manager was installed and not a specific version. Since the main branch may contain breaking changes or bugs, the ComfyUI Manager is now installed with a specific version (v2.55.5).
8+
- The ComfyUI Manager installs its dependencies when it is first launched. This means that the dependencies have to be installed every time the container is started. To avoid this, the dependencies are now installed manually during the image build process.
9+
- The directory structure of the ComfyUI models directory is now automatically created upon container startup if it does not exist.
10+
- The Docker image now has two more tags: one with the ComfyUI version and the second with the ComfyUI and ComfyUI Manager versions that are installed in the image. This makes it easier for users to find out which ComfyUI version they are installing before pulling the image.
11+
- A section was added to the read me, which explains how to update the local image to the latest version.
12+
13+
## v0.1.0 (November 28, 2024)
14+
15+
- Created a Docker image for running ComfyUI.
16+
- The image includes ComfyUI and ComfyUI Manager.
17+
- The image is based on the latest version of the PyTorch image.
18+
- A GitHub Actions workflow is used to automatically build and publish the Docker image to the GitHub Container Registry when a release is created.

Dockerfile

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,38 @@ RUN apt update --assume-yes && \
77
apt install --assume-yes git
88

99
# Clones the ComfyUI repository and checks out the latest release
10-
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \
10+
RUN git clone https://github.com/comfyanonymous/ComfyUI.git /opt/comfyui && \
1111
cd /opt/comfyui && \
12-
git checkout tags/v0.3.4
12+
git checkout tags/v0.3.7
13+
14+
# Clones the ComfyUI Manager repository and checks out the latest release; ComfyUI Manager is an extension for ComfyUI that enables users to install
15+
# custom nodes and download models directly from the ComfyUI interface; instead of installing it to "/opt/comfyui/custom_nodes/ComfyUI-Manager", which
16+
# is the directory it is meant to be installed in, it is installed to its own directory; the entrypoint will symlink the directory to the correct
17+
# location upon startup; the reason for this is that the ComfyUI Manager must be installed in the same directory that it installs custom nodes to, but
18+
# this directory is mounted as a volume, so that the custom nodes are not installed inside of the container and are not lost when the container is
19+
# removed; this way, the custom nodes are installed on the host machine
20+
RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /opt/comfyui-manager && \
21+
cd /opt/comfyui-manager && \
22+
git checkout tags/2.55.5
23+
24+
# Installs the required Python packages for both ComfyUI and the ComfyUI Manager
25+
RUN pip install \
26+
--requirement /opt/comfyui/requirements.txt \
27+
--requirement /opt/comfyui-manager/requirements.txt
1328

1429
# Sets the working directory to the ComfyUI directory
1530
WORKDIR /opt/comfyui
1631

17-
# Installs the required Python packages
18-
RUN pip install -r requirements.txt
19-
20-
# Installs the ComfyUI Manager, which is an extension for ComfyUI that makes it possible to install, remove, disable, and enable various custom nodes
21-
RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git custom_nodes/ComfyUI-Manager
22-
2332
# Exposes the default port of ComfyUI (this is not actually exposing the port to the host machine, but it is good practice to include it as metadata,
2433
# so that the user knows which port to publish)
2534
EXPOSE 8188
2635

36+
# Adds the startup script to the container; the startup script will create all necessary directories in the models and custom nodes volumes that were
37+
# mounted to the container and symlink the ComfyUI Manager to the correct directory
38+
ADD entrypoint.sh /entrypoint.sh
39+
ENTRYPOINT ["/bin/bash", "/entrypoint.sh"]
40+
2741
# On startup, ComfyUI is started at its default port; the IP address is changed from localhost to 0.0.0.0, because Docker is only forwarding traffic
2842
# to the IP address it assigns to the container, which is unknown at build time; listening to 0.0.0.0 means that ComfyUI listens to all incoming
2943
# traffic; the auto-launch feature is disabled, because we do not want (nor is it possible) to open a browser window in a Docker container
30-
CMD ["python", "main.py", "--listen", "0.0.0.0", "--port", "8188", "--disable-auto-launch"]
44+
CMD ["/opt/conda/bin/python", "main.py", "--listen", "0.0.0.0", "--port", "8188", "--disable-auto-launch"]

README.md

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,15 @@ docker run \
1717
--name comfyui \
1818
--detach \
1919
--restart unless-stopped \
20-
--volume <path/to/models/folder>:/opt/comfyui/models \
20+
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
21+
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
2122
--publish 8188:8188 \
2223
--runtime nvidia \
2324
--gpus all \
2425
ghcr.io/lecode-official/comfyui-docker:latest
2526
```
2627

27-
Please note, that the `<path/to/models/folder>` must be replaced with a path to a folder on the host system where the models will be stored, e.g., `$HOME/.comfyui`.
28+
Please note, that the `<path/to/models/folder>` and `<path/to/custom/nodes/folder>` must be replaced with paths to directories on the host system where the models and custom nodes will be stored, e.g., `$HOME/.comfyui/models` and `$HOME/.comfyui/custom-nodes`, which can be created like so: `mkdir -p $HOME/.comfyui/{models,custom-nodes}`.
2829

2930
The `--detach` flag causes the container to run in the background and `--restart unless-stopped` configures the Docker Engine to automatically restart the container if it stopped itself, experienced an error, or the computer was shutdown, unless you explicitly stopped the container using `docker stop`. This means that ComfyUI will be automatically started in the background when you boot your computer. The `--runtime nvidia` and `--gpus all` arguments enable ComfyUI to access the GPUs of your host system. If you do not want to expose all GPUs, you can specify the desired GPU index or ID instead.
3031

@@ -37,6 +38,29 @@ docker stop comfyui
3738
docker rm comfyui
3839
```
3940

41+
## Updating
42+
43+
To update ComfyUI Docker to the latest version you have to first stop the running container, then pull the new version, optionally remove dangling images, and then restart the container:
44+
45+
```shell
46+
docker stop comfyui
47+
docker rm comfyui
48+
49+
docker pull ghcr.io/lecode-official/comfyui-docker:latest
50+
docker image prune # Optionally remove dangling images
51+
52+
docker run \
53+
--name comfyui \
54+
--detach \
55+
--restart unless-stopped \
56+
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
57+
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
58+
--publish 8188:8188 \
59+
--runtime nvidia \
60+
--gpus all \
61+
ghcr.io/lecode-official/comfyui-docker:latest
62+
```
63+
4064
## Building
4165

4266
If you want to use the bleeding edge development version of the Docker image, you can also clone the repository and build the image yourself:
@@ -53,7 +77,8 @@ docker run \
5377
--name comfyui \
5478
--detach \
5579
--restart unless-stopped \
56-
--volume <path/to/models/folder>:/opt/comfyui/models \
80+
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
81+
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
5782
--publish 8188:8188 \
5883
--runtime nvidia \
5984
--gpus all \

entrypoint.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
3+
# Creates the directories for the models inside of the volume that is mounted from the host
4+
MODEL_DIRECTORIES=(
5+
"checkpoints"
6+
"clip"
7+
"clip_vision"
8+
"configs"
9+
"controlnet"
10+
"diffusers"
11+
"diffusion_models"
12+
"embeddings"
13+
"gligen"
14+
"hypernetworks"
15+
"loras"
16+
"photomaker"
17+
"style_models"
18+
"text_encoders"
19+
"unet"
20+
"upscale_models"
21+
"vae"
22+
"vae_approx"
23+
)
24+
for MODEL_DIRECTORY in ${MODEL_DIRECTORIES[@]}; do
25+
mkdir -p /opt/comfyui/models/$MODEL_DIRECTORY
26+
done
27+
28+
# Creates the symlink for the ComfyUI Manager to the custom nodes directory, which is also mounted from the host
29+
rm --force /opt/comfyui/custom_nodes/ComfyUI-Manager
30+
ln -s \
31+
/opt/comfyui-manager \
32+
/opt/comfyui/custom_nodes/ComfyUI-Manager

0 commit comments

Comments
 (0)