Skip to content

Add local Docker support#9305

Open
bbergeron0 wants to merge 21 commits intoComfy-Org:masterfrom
bbergeron0:master
Open

Add local Docker support#9305
bbergeron0 wants to merge 21 commits intoComfy-Org:masterfrom
bbergeron0:master

Conversation

@bbergeron0
Copy link

@bbergeron0 bbergeron0 commented Aug 12, 2025

Description

Introduce a Docker stack to run ComfyUI inside a container. This PR attempts to keep everything minimal, documented, and easy to maintain. I'm also committed to provide maintenance support regarding the Docker stack, and I've added my name to CODEOWNER to assist in future PR touching the Docker stack (it look likes CODEOWNERS was purged upstream to only include the two project admins, so I'll let the owners suggest how I can help them instead).

Features

  • All of ComfyUI's features
  • File ownership synchronization between the host and the ComfyUI containers
  • Automatic installation of ComfyUI and custom nodes dependencies
  • Allow defining additional python and system dependencies in case some custom node packs don't provide (or provide incomplete) requirement files
  • Support for ComfyUI manager
  • Support for mounting and persisting models, custom nodes, and user-generated data
  • Support for hardware acceleration (See "Testing" section bellow)
  • Podman support

Anti-Features

These are things this PR will not introduce unless explicitly requested by code owners. These anti-features are listed to keep the Docker stack minimal and unopinionated:

  • Anything ComfyUI or the ComfyUI Manager already provides in some capacity. This includes building-in, downloading, or managing models, custom nodes, or workflows.
  • Support for hardware or use cases not natively supported by ComfyUI
  • Infrastructure to publish Docker images on Docker Hub. I think it would be better to start by merging just a local Docker stack, and then add Docker Hub infra in another PR.
  • New features

TL;DR: This is Docker support and nothing more, with minimal maintenance costs. Users who want more from ComfyUI should look at the alternative projects listed at the end.

Motivation

While ComfyUI does well in terms of security and monitoring, we cannot catch everything, and the last line of defense should be to avoid running arbitrary software like custom node packs on host machines, hence why I propose offering a Docker image.

Furthermore, the need for an official ComfyUI Docker image (or at least some form of Docker compatibility) has been expressed multiple times, as evidenced by various issues and discussions. This demand is further demonstrated by other forks, repositories, and pull requests with similar goals to this one.

Known issues

  • Users can't persistently update ComfyUI from within the container because ComfyUI's installation directory is not mapped to a volume and does not persist across container reboots. This renders features like ComfyUI Manager's software update feature useless.
  • I recognize that several users have already created ad-hoc Dockerfiles for ComfyUI inside their repositories, so there might be merge conflicts on their end.
  • docker-compose.yaml is both a tracked and a user-editable file. Cautiousness will be required when committing.

Testing

HELP NEEDED: I don't have AMD hardware to test this image, so if anyone could assist with testing on AMD systems, I am willing to integrate AMD support before merging. Also, I only have one SD-capable computer, so contributions for broader testing would be appreciated.

Please read the "Running with Docker" section in README.md before testing. When commenting, please mention:

  • Your Operating System (If on Windows, mention your WSL distro)
  • Your Podman/Docker version
  • Your GPU
  • Your cloud computing environment, if applicable
  • Any changes you made to the configuration or the code
  • If you've encountered any error or warning, copy/paste the message and tell me whether it happened at buildtime or at runtime

Tested

  • OS: Gentoo, Ubuntu 24, RHEL9, Debian 13, Windows 11, WSL
  • Engines: Docker (Buildkit), Docker (Legacy), Podman
  • Hardware: RTX 3060, RTX 3070 Ti, RTX 2060
  • Features: ComfyUI Manager, custom nodes, custom pip dependencies & custom system dependencies

I've been daily-driving this setup since before that PR so I can attest that all the ComfyUI features (at least those that I've used so far) are operational.

Alternatives

Pull Requests

This PR competes with three others that I know of:

  • docker #530, which is two years old, offers fewer features, and is less documented in my opinion.
  • Dockerfile and automatic generation of images via GitHub Actions #1469, which is also old and less feature-rich, but importantly introduces GitHub Actions, which I believe would increase maintenance costs unnecessarily. If we eventually want to use Docker actions to publish ComfyUI images, I believe it would be wiser to start with the smaller step of distributing a local setup, then work, test, and debug our way toward GitHub Actions incrementally.
  • add docker config file #6993, which appears to be a potential supply chain attack.

Projects

Other projects that combine ComfyUI and Docker:

  • akitaonrails/ComfyUI-Docker-CUDA-preloaded Which is a collection of scripts and configuration files to build, run and maintain a ComfyUI image. Also offers a model downloader.
  • YanWenKun/ComfyUI-Docker Which introduce docker support and publish a few image variants on Docker Hub. Come with ComfyUI manager and a few models and custom node packs built-in for certain images.

@Ambrosiussen
Copy link

Thanks for making this PR. I'm going to give this a try on Win11 with a RTX4090.
I think it would be good to also modify the README.md in this PR so people without prior docker experience know how to run this :)

@Ambrosiussen
Copy link

Tried your latest changes - entrypoint.sh is not mounted in the container. So following your README steps 1:1 results in an error.

 ✔ Network comfyui_default  Created                                                                                0.0s
 ✔ Container comfyui        Created                                                                                8.2s
Attaching to comfyui
comfyui  | exec ./entrypoint.sh: no such file or directory```

@bbergeron0
Copy link
Author

bbergeron0 commented Aug 13, 2025

Tried your latest changes - entrypoint.sh is not mounted in the container. So following your README steps 1:1 results in an error.

 ✔ Network comfyui_default  Created                                                                                0.0s
 ✔ Container comfyui        Created                                                                                8.2s
Attaching to comfyui
comfyui  | exec ./entrypoint.sh: no such file or directory```

@Ambrosiussen That's strange; the image shouldn't have even completed its build if entrypoint.sh wasn't copied properly. Could you add these lines at the bottom of the Dockerfile, remove the "command" field in docker-compose.yaml, and share the new output?

ENTRYPOINT []
CMD pwd; ls -la

edit:
docker compose build output would help too. Thanks in advance!

@Ambrosiussen
Copy link

Okay so I tried a couple things:

  1. Did what you suggested:
comfyui exited with code 0(base) PS H:\Github\ComfyUI> docker compose up
[+] Running 1/1
 ✔ Container comfyui  Recreated                                                                                    1.4s
Attaching to comfyui
comfyui  | /comfyui
comfyui  | total 452
comfyui  | drwxr-xr-x  1 comfyui comfyui   4096 Aug 14 08:15 .
comfyui  | drwxr-xr-x  1 root    root      4096 Aug 14 08:15 ..
comfyui  | drwxr-xr-x  5 root    root      4096 Aug 13 11:17 .ci
comfyui  | -rwxr-xr-x  1 root    root       715 Aug 13 18:44 .dockerignore
comfyui  | drwxr-xr-x  7 root    root      4096 Aug 13 21:19 .git
comfyui  | -rwxr-xr-x  1 root    root       115 Aug 13 11:17 .gitattributes
comfyui  | drwxr-xr-x  4 root    root      4096 Aug 13 11:17 .github
comfyui  | -rwxr-xr-x  1 root    root       478 Aug 13 18:44 .gitignore
comfyui  | drwxr-xr-x  6 comfyui comfyui   4096 Aug 13 19:01 .venv
comfyui  | -rwxr-xr-x  1 root    root      1536 Aug 13 11:17 CODEOWNERS
comfyui  | -rwxr-xr-x  1 root    root      1923 Aug 13 11:17 CONTRIBUTING.md
comfyui  | -rwxr-xr-x  1 root    root      2899 Aug 13 21:19 Dockerfile
comfyui  | -rwxr-xr-x  1 root    root     35823 Aug 13 11:17 LICENSE
comfyui  | -rwxr-xr-x  1 root    root     27759 Aug 13 18:44 README.md
comfyui  | -rwxr-xr-x  1 root    root      3314 Aug 13 11:17 alembic.ini
comfyui  | drwxr-xr-x  2 root    root      4096 Aug 13 11:17 alembic_db
comfyui  | drwxr-xr-x  5 root    root      4096 Aug 13 11:17 api_server
comfyui  | drwxr-xr-x  3 root    root      4096 Aug 13 11:17 app
comfyui  | drwxr-xr-x 13 root    root      4096 Aug 13 18:44 comfy
comfyui  | drwxr-xr-x 10 root    root      4096 Aug 13 11:17 comfy_api
comfyui  | drwxr-xr-x  4 root    root      4096 Aug 13 11:17 comfy_api_nodes
comfyui  | drwxr-xr-x  2 root    root      4096 Aug 13 11:17 comfy_config
comfyui  | drwxr-xr-x  2 root    root      4096 Aug 13 11:17 comfy_execution
comfyui  | drwxr-xr-x  3 root    root      4096 Aug 13 18:44 comfy_extras
comfyui  | -rwxr-xr-x  1 root    root       131 Aug 13 18:44 comfyui_version.py
comfyui  | -rwxr-xr-x  1 root    root      3665 Aug 13 11:17 cuda_malloc.py
comfyui  | drwxrwxrwx  1 root    root      4096 Aug 13 19:07 custom_nodes
comfyui  | -rwxr-xr-x  1 root    root      1470 Aug 13 21:19 docker-compose.yml
comfyui  | -rwxrwxrwx  1 root    root      2772 Aug 13 18:44 entrypoint.sh
comfyui  | -rwxr-xr-x  1 root    root     52864 Aug 13 11:17 execution.py
comfyui  | -rwxr-xr-x  1 root    root      1527 Aug 13 11:17 extra_model_paths.yaml.example
comfyui  | -rwxr-xr-x  1 root    root     16332 Aug 13 11:17 folder_paths.py
comfyui  | -rwxr-xr-x  1 root    root       383 Aug 13 11:17 hook_breaker_ac10a0.py
comfyui  | lrwxrwxrwx  1 comfyui comfyui     11 Aug 13 21:43 input -> /data/input
comfyui  | -rwxr-xr-x  1 root    root      4457 Aug 13 11:17 latent_preview.py
comfyui  | -rwxr-xr-x  1 root    root     15035 Aug 13 11:17 main.py
comfyui  | drwxrwxrwx  1 root    root      4096 Aug 13 11:17 models
comfyui  | -rwxr-xr-x  1 root    root      1296 Aug 13 11:17 new_updater.py
comfyui  | -rwxr-xr-x  1 root    root      1744 Aug 13 11:17 node_helpers.py
comfyui  | -rwxr-xr-x  1 root    root    100720 Aug 13 11:17 nodes.py
comfyui  | lrwxrwxrwx  1 comfyui comfyui     12 Aug 13 21:43 output -> /data/output
comfyui  | -rwxr-xr-x  1 root    root       136 Aug 13 11:17 protocol.py
comfyui  | -rwxr-xr-x  1 root    root       702 Aug 13 18:44 pyproject.toml
comfyui  | -rwxr-xr-x  1 root    root       236 Aug 13 11:17 pytest.ini
comfyui  | -rwxr-xr-x  1 root    root       450 Aug 13 18:44 requirements.txt
comfyui  | drwxr-xr-x  2 root    root      4096 Aug 13 11:17 script_examples
comfyui  | -rwxr-xr-x  1 root    root     42678 Aug 13 11:17 server.py
comfyui  | lrwxrwxrwx  1 comfyui comfyui     10 Aug 13 21:43 temp -> /data/temp
comfyui  | drwxr-xr-x  4 root    root      4096 Aug 13 11:17 tests
comfyui  | drwxr-xr-x 12 root    root      4096 Aug 13 11:17 tests-unit
comfyui  | lrwxrwxrwx  1 comfyui comfyui     10 Aug 13 21:43 user -> /data/user
comfyui  | drwxr-xr-x  2 root    root      4096 Aug 13 11:17 utils
comfyui exited with code 0
  1. Changed the command in compose:
    from command: /comfyui/entrypoint.sh to command: /bin/bash /comfyui/entrypoint.sh. Then it runs entrypoint.

  2. You will want to add -u at the top of the bash script, so the line endings are correctly interpreted on Windows (This is only a problem for people who clone your PR, not you locally since your IDE already knows whats up):
    #!/bin/sh -u (Even better, change the .gitattributes for that file. Simply add *.sh text eol=lf
    Otherwise you run into:

(base) PS H:\Github\ComfyUI> docker compose up
[+] Running 1/1
 ✔ Container comfyui  Recreated                                                                                    0.2s
Attaching to comfyui
comfyui  | /comfyui/entrypoint.sh: line 2: $'\r': command not found
comfyui  | /comfyui/entrypoint.sh: line 8: $'\r': command not found
: invalid optionyui/entrypoint.sh: line 9: set: -
comfyui  | set: usage: set [-abefhkmnptuvxBCEHPT] [-o option-name] [--] [-] [arg ...]
comfyui  | /comfyui/entrypoint.sh: line 10: $'\r': command not found
comfyui  | /comfyui/entrypoint.sh: line 13: $'\r': command not found
comfyui  | /comfyui/entrypoint.sh: line 36: syntax error near unexpected token `$'do\r''
'omfyui  | /comfyui/entrypoint.sh: line 36: `for dev in /dev/nvidia*; do
comfyui exited with code 2
  1. Once that is fixed, entrypoint runs into:
(base) PS H:\Github\ComfyUI> docker compose up
Attaching to comfyui
comfyui  | [entrypoint] Setting user UID and GID...
comfyui  | [entrypoint] Changing directory ownership...
comfyui  | [entrypoint] Adding user to GPU device groups...
comfyui  | ls: cannot access '/dev/nvidia*': No such file or directory
comfyui  | [entrypoint] Installing new python dependencies, this might take a while...
comfyui  | [entrypoint] Running command
comfyui exited with code 0

@bbergeron0
Copy link
Author

I believe I figured it out. The error message exec ./entrypoint.sh: no such file or directory is misleading because entrypoint.sh does exist -- but its interpreter does not. With correct LF line endings, the interpreter is /bin/sh. However, when the file is checked out with CRLF endings, the interpreter path becomes /bin/sh\r, which explains why it works when you explicitly run it with /bin/bash /comfyui/entrypoint.sh.

Theoretically, adding the .gitattributes rule you mentioned should fix the issue.

I’ll push a fix soon. After that, you can run:

git pull
git checkout -- entrypoint.sh
docker compose build
docker compose up

@bbergeron0
Copy link
Author

What’s catching my attention now is the message: ls: cannot access '/dev/nvidia*': No such file or directory. Does this error also occur after applying the previous fix?

@yt-koike
Copy link

Hello, I'm @yt-koike, the starter of PR named Please publish Docker image with GitHub workflow.

I appreciate @bbergeron0 and @Ambrosiussen s' good job and I am willing to help you all!
I built and run the Docker container with your code and it worked marvelously on my PC with NVIDIA GeForce RTX 3070 Ti and CUDA 12.8 installed.

As my first contribution to this PR, I make some little suggestions as follows to make the code better.

  1. Renaming docker-compose.yml to compose.yaml

Docker officially says compose file should be named as compose.yaml in the Docker manual so please consider renaming the file. Of course, you can leave it if you value the backwards compatibility of earlier Docker more than that.

  1. Shortening the starter command

As you possibly know, the following commands can be shortened as docker compose up --build.

docker compose build
docker compose up

If the user does not modify the code at all and there's no need to build the image on every start, docker compose up would single-handedly do the job.

Thank you :)

@Ambrosiussen
Copy link

Ambrosiussen commented Aug 24, 2025

Just to provide my update - latest version of the PR works well!
I still get the same nvidia error, but compute works just fine.

EDIT: There is actually one change I would propose, as this is something you have to do for custom nodes, workflows (user scene files) and python venvs to work.

In the compose under volumes, you should just mount the entire comfy folder to the container.
Easiest is like this:
.:- .:/comfyui:rw

@bbergeron0
Copy link
Author

bbergeron0 commented Aug 24, 2025

Hi @yt-koike, thanks for your support! I'll add your hardware to the "testing" section of my PR. Could you also provide your OS? (I assume "PC" implies Windows 11, but I just want to be sure.)

  1. Renaming docker-compose.yml to compose.yaml

I've never seen a compose.yaml file before, but since that's the official recommendation, I agree with renaming it.

  1. Shortening the starter command

I'm planning on improving the documentation, so I'll see whether I shorten it for convenience or expand it for clarity and explanation.

@Ambrosiussen Thanks for the feedback. If I understand correctly, you're still seeing the ls: cannot access '/dev/nvidia*': No such file or directory error message, but hardware acceleration (CUDA, compute, etc.) still works anyway? I'm a bit confused because this error message shouldn't appear, and if it does, ComfyUI normally shouldn't launch or work. Could you try again after reverting your local changes to Dockerfile, docker-compose.yaml, and entrypoint.sh (if any), and flushing the previous volumes with docker compose down -v? Also, what's your Docker version?

In the compose under volumes, you should just mount the entire comfy folder to the container.

The Dockerfile already creates persistent volumes for user-generated data (input, output, temp, user), the virtual environment, custom nodes, models, and the ComfyUI user. The volumes worth mounting are documented inside docker-compose.yaml:

volumes:
  # Share custom nodes and models with the container.
  - ./custom_nodes:/comfyui/custom_nodes
  - ./models:/comfyui/models
  # Optional: mount the user data directory.
  #- data:/data/

I thought about it previously, but I decided against it. Some parts of the ComfyUI folders are meant to be immutable (i.e. the code), and unexpected behavior can occur if these files get overwritten and fall out of sync with the image after an update. It's also a security decision: the less data malicious custom node packs can persistently modify, the easier they are to contain. This is why I start by persisting the minimum possible, though I concede this comes at the cost of some convenience.

Maybe users would prefer to have everything mutable inside a single mountable "/data" folders?

@bbergeron0 bbergeron0 force-pushed the master branch 2 times, most recently from 20be04f to d343a7f Compare August 25, 2025 01:35
@yt-koike
Copy link

yt-koike commented Aug 25, 2025

Could you also provide your OS?

Sure, it's Ubuntu 24.04.3 LTS. I have my best GPU in that machine because Linux offers a very customable environment for developing.

I also have another computer which has Windows 11 and a NVIDIA GPU in, so let me check if ComfyUI works on it.

@icsy7867
Copy link

icsy7867 commented Aug 25, 2025

Trying to build using podman on RHEL9.

I got an error trying to build the dockerfile due to permissions on requirements.txt. I had to switch to root, chown it and switch back:

COPY requirements.txt ./
USER root
RUN chown comfyui requirements.txt
USER comfyui

This would probably be cleaner to add all of the files as root, and then chown them all to comfyui.

And...
in the Dockerfile, trying to create a symlink to the current directory fails because the folders already exist. I had to remove them when building via podman on RHEL9

COPY . .
RUN rm -rf /data/input && rm -rf /data/output
RUN ln -sf /data/* .

Also, on FIPS enabled system, this line will cause an issue in the requirements.txt file. The newest versions have an issue with fips.

av>=14.2.0

If you set this to 14.2.0 or 14.1.0 I believe it should work.

@bbergeron0
Copy link
Author

Hi @icsy7867, thanks for the feedback. Podman and non-BuildKit builds aren’t part of my goals, but I’ll see what I can do. After a few tweaks, I managed to build the image using both Podman and the legacy builder.

I got an error trying to build the Dockerfile due to permissions on requirements.txt.

Could you please pull the latest changes and try again? If the error persists, could you share the full error message?

In the Dockerfile, trying to create a symlink to the current directory fails because the folders already exist.

This shouldn’t happen given the .dockerignore file. Could you re-try and, if it still fails, share the error message, your Podman/Compose/Docker version along with the exact command you used?

Also, on FIPS-enabled systems, this line will cause an issue in the requirements.txt file. The newest versions have an issue with FIPS.

Unless this issue occurs specifically inside the Docker image, addressing it would be outside the scope of this PR. It might be better to open an issue in the tracker or raise it on Discord. I’m not familiar with FIPS, and I’d prefer not to make changes that affect the main developers' code or dependencies.

@icsy7867
Copy link

Hi @icsy7867, thanks for the feedback. Podman and non-BuildKit builds aren’t part of my goals, but I’ll see what I can do. After a few tweaks, I managed to build the image using both Podman and the legacy builder.

I got an error trying to build the Dockerfile due to permissions on requirements.txt.

Could you please pull the latest changes and try again? If the error persists, could you share the full error message?

In the Dockerfile, trying to create a symlink to the current directory fails because the folders already exist.

This shouldn’t happen given the .dockerignore file. Could you re-try and, if it still fails, share the error message, your Podman/Compose/Docker version along with the exact command you used?

Also, on FIPS-enabled systems, this line will cause an issue in the requirements.txt file. The newest versions have an issue with FIPS.

Unless this issue occurs specifically inside the Docker image, addressing it would be outside the scope of this PR. It might be better to open an issue in the tracker or raise it on Discord. I’m not familiar with FIPS, and I’d prefer not to make changes that affect the main developers' code or dependencies.

Fair enough. But FIPS breaking will prevent this from running on anything enterprise. But perhaps that should be a different PR.

open-webui/open-webui#15720

Same thing here. Basically using AV < 15.0.0 should work fine.

Ill try and pull and rebuild soon!

@NN708
Copy link

NN708 commented Dec 13, 2025

This PR has been open for a few months now, and seems stable at least on NVIDIA setups. @comfyanonymous Would you consider merging it, or is there anything else still needed?

@IARI
Copy link

IARI commented Jan 9, 2026

@bbergeron0
Do you think theres a way to have the comfy org team merge this any time?
Is there any way to support this?

@bbergeron0
Copy link
Author

@NN708 @IARI

To be honest, I haven’t heard anything from any member of the ComfyUI team—neither here, on Matrix, nor on Discord.

I’ve set the PR aside lately because of the holiday season and because my GPU needs repair, but I must admit I’m growing eager for this PR to move forward.

I don’t have an answer to your question, and I don’t think it will go anywhere without first catching the attention of the ComfyUI team, which I no longer know how to reach.

The best way to support this PR would be to find a ComfyUI member interested in looking into it. If anyone knows someone in their leadership, please let me know.

@pfn
Copy link

pfn commented Jan 17, 2026

for nvidia cuda130, it seems that the pytorch install doesn't pull from pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu130

@comfy-pr-bot
Copy link
Member

Test Evidence Check

⚠️ Warning: Visual Documentation Missing

If this PR changes user-facing behavior, visual proof (screen recording or screenshot) is required. PRs without applicable visual documentation may not be reviewed until provided.

You can add it by:

  • GitHub: Drag & drop media directly into the PR description
  • YouTube: Include a link to a short demo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.