Skip to content

A Docker image for ComfyUI, which makes it extremely easy to run ComfyUI on Linux and Windows WSL2.

License

Notifications You must be signed in to change notification settings

lecode-official/comfyui-docker

Repository files navigation

ComfyUI Docker

This is a Docker image for ComfyUI, which makes it extremely easy to run ComfyUI on Linux and Windows WSL2. The image also includes the ComfyUI Manager extension.

Getting Started

To get started, you have to install Docker. This can be either Docker Engine, which can be installed by following the Docker Engine Installation Manual or Docker Desktop, which can be installed by downloading the installer for your operating system.

To enable the usage of NVIDIA GPUs, the NVIDIA Container Toolkit must be installed. The installation process is detailed in the official documentation

Installation

The ComfyUI Docker image is available from the GitHub Container Registry. Installing ComfyUI is as simple as pulling the image and starting a container, which can be achieved using the following command:

docker run \
    --name comfyui \
    --detach \
    --restart unless-stopped \
    --env USER_ID="$(id -u)" \
    --env GROUP_ID="$(id -g)" \
    --volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
    --volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
    --publish 8188:8188 \
    --runtime nvidia \
    --gpus all \
    ghcr.io/lecode-official/comfyui-docker:latest

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}.

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.

After the container has started, you can navigate to localhost:8188 to access ComfyUI.

If you want to stop ComfyUI, you can use the following commands:

docker stop comfyui
docker rm comfyui

Warning

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.

Updating

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:

docker stop comfyui
docker rm comfyui

docker pull ghcr.io/lecode-official/comfyui-docker:latest
docker image prune # Optionally remove dangling images

docker run \
    --name comfyui \
    --detach \
    --restart unless-stopped \
    --env USER_ID="$(id -u)" \
    --env GROUP_ID="$(id -g)" \
    --volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
    --volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
    --publish 8188:8188 \
    --runtime nvidia \
    --gpus all \
    ghcr.io/lecode-official/comfyui-docker:latest

Building

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:

git clone https://github.com/lecode-official/comfyui-docker.git
docker build --tag lecode/comfyui-docker:latest comfyui-docker

Now, a container can be started like so:

docker run \
    --name comfyui \
    --detach \
    --restart unless-stopped \
    --env USER_ID="$(id -u)" \
    --env GROUP_ID="$(id -g)" \
    --volume "<path/to/models/folder>:/opt/comfyui/models:rw" \
    --volume "<path/to/custom/nodes/folder>:/opt/comfyui/custom_nodes:rw" \
    --publish 8188:8188 \
    --runtime nvidia \
    --gpus all \
    lecode/comfyui-docker:latest

License

The ComfyUI Docker image is licensed under the MIT License. ComfyUI and the ComfyUI Manager are both licensed under the GPL 3.0 license.

About

A Docker image for ComfyUI, which makes it extremely easy to run ComfyUI on Linux and Windows WSL2.

Resources

License

Stars

Watchers

Forks

Packages