Skip to content

Commit 4fe0c81

Browse files
alex-marinovlecode-official
authored andcommitted
Add Docker Compose support and update README for output directory
1 parent 37a0517 commit 4fe0c81

File tree

2 files changed

+92
-1
lines changed

2 files changed

+92
-1
lines changed

README.md

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@ docker run \
2121
--env GROUP_ID="$(id -g)" \
2222
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
2323
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
24+
--volume "<path/to/output/folder>:/opt/comfyui/output:rw" \
2425
--publish 8188:8188 \
2526
--runtime nvidia \
2627
--gpus all \
2728
ghcr.io/lecode-official/comfyui-docker:latest
2829
```
2930

30-
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}`.
31+
Please note, that the `<path/to/models/folder>`, `<path/to/custom/nodes/folder>` and `<path/to/output/folder>` must be replaced with paths to directories on the host system where the models, custom nodes and generated outputs (images, workflows, etc.) will be stored, e.g., `$HOME/.comfyui/models`, `$HOME/.comfyui/custom-nodes` and `$HOME/.comfyui/output`, which can be created like so: `mkdir -p $HOME/.comfyui/{models,custom-nodes,output}`.
3132

3233
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 two `--env` arguments inject the user ID and group ID of the current host user into the container. During startup, a user with the same user ID and group ID will be created, and ComfyUI will be run using this user. This ensures that files written to the volumes (e.g., models and custom nodes installed with the ComfyUI Manager) will be owned by the host system's user. Normally, the user inside the container is `root`, which means that the files that are written from the container to the host system are also owned by `root`. If you have run ComfyUI Docker without setting the environment variables, then you may have to change the owner of the files in the models and custom nodes directories: `sudo chown -r "$(id -un):$(id -gn)" <path/to/models/folder> <path/to/custom/nodes/folder>`. 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.
3334

@@ -43,6 +44,54 @@ docker rm comfyui
4344
> [!WARNING]
4445
> While the custom nodes themselves are installed outside of the container, their requirements are installed inside of the container. This means that stopping and removing the container will remove the installed requirements. When the container is started again, the requirements will be automatically installed, but this may, depending on the number of custom nodes and their requirements, take some time.
4546
47+
## Docker Compose
48+
49+
Instead of using `docker run`, you can use the provided `docker-compose.yml` in this repository for easier management and updates.
50+
51+
1. (First time) Create the required host directories:
52+
```shell
53+
mkdir -p $HOME/.comfyui/{models,custom-nodes,output}
54+
```
55+
2. (Optional) Create a `.env` file next to `docker-compose.yml` to pin your user / group IDs:
56+
```shell
57+
echo "UID=$(id -u)" > .env
58+
echo "GID=$(id -g)" >> .env
59+
```
60+
If omitted, the defaults `1000` / `1000` in the compose file are used.
61+
3. Start (or bring up after changes):
62+
```shell
63+
docker compose up -d
64+
```
65+
4. View logs:
66+
```shell
67+
docker compose logs -f
68+
```
69+
5. Update later:
70+
```shell
71+
docker compose pull
72+
docker compose up -d
73+
```
74+
6. Stop / remove the container (keeps your data in the host directories):
75+
```shell
76+
docker compose down
77+
```
78+
79+
Custom CLI arguments: edit the `command:` line in `docker-compose.yml` (uncomment or add) e.g.:
80+
```yaml
81+
command: ["--enable-cors-header", "*"]
82+
```
83+
Then apply changes:
84+
```shell
85+
docker compose up -d --force-recreate
86+
```
87+
88+
Migrating existing outputs from a previously created container (non‑compose):
89+
```shell
90+
docker cp comfyui:/opt/comfyui/output/. $HOME/.comfyui/output/
91+
```
92+
93+
After this, you can remove the old container and strictly use compose.
94+
4695
## Updating
4796

4897
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:
@@ -62,6 +111,7 @@ docker run \
62111
--env GROUP_ID="$(id -g)" \
63112
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
64113
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
114+
--volume "<path/to/output/folder>:/opt/comfyui/output:rw" \
65115
--publish 8188:8188 \
66116
--runtime nvidia \
67117
--gpus all \
@@ -79,13 +129,20 @@ docker run \
79129
--env GROUP_ID="$(id -g)" \
80130
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
81131
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
132+
--volume "<path/to/output/folder>:/opt/comfyui/output:rw" \
82133
--publish 8188:8188 \
83134
--runtime nvidia \
84135
--gpus all \
85136
ghcr.io/lecode-official/comfyui-docker:latest \
86137
--enable-cors-header <origin>
87138
```
88139

140+
With Docker Compose:
141+
```shell
142+
docker compose up -d --force-recreate
143+
```
144+
(Add or edit the `command:` line in the compose file.)
145+
89146
## Building
90147

91148
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:
@@ -107,6 +164,7 @@ docker run \
107164
--env GROUP_ID="$(id -g)" \
108165
--volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
109166
--volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
167+
--volume "<path/to/output/folder>:/opt/comfyui/output:rw" \
110168
--publish 8188:8188 \
111169
--runtime nvidia \
112170
--gpus all \

docker-compose.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
services:
2+
comfyui:
3+
image: ghcr.io/lecode-official/comfyui-docker:latest
4+
container_name: comfyui
5+
restart: unless-stopped
6+
environment:
7+
USER_ID: "${UID:-1000}"
8+
GROUP_ID: "${GID:-1000}"
9+
ports:
10+
- "8188:8188"
11+
volumes:
12+
- ${HOME}/.comfyui/models:/opt/comfyui/models:rw
13+
- ${HOME}/.comfyui/custom-nodes:/opt/comfyui/custom_nodes:rw
14+
- ${HOME}/.comfyui/output:/opt/comfyui/output:rw
15+
# Optional: pass extra ComfyUI CLI args (example shown commented)
16+
# command: ["--enable-cors-header", "*"]
17+
deploy:
18+
resources:
19+
reservations:
20+
devices:
21+
- driver: nvidia
22+
count: all
23+
capabilities: [gpu]
24+
25+
# Usage:
26+
# 1. (Optional) Create a .env file alongside this compose file with:
27+
# UID=$(id -u)
28+
# GID=$(id -g)
29+
# 2. Ensure directories exist:
30+
# mkdir -p "$HOME/.comfyui"/{models,custom-nodes,output}
31+
# 3. Start: docker compose up -d
32+
# 4. Update image later: docker compose pull && docker compose up -d
33+
# 5. View logs: docker compose logs -f

0 commit comments

Comments
 (0)