Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions source/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

# Defines build arguments for the versions of PyTorch, CUDA, and cuDNN to use
ARG PYTORCH_VERSION=2.9.1
ARG CUDA_VERSION=12.8
ARG PYTORCH_VERSION=2.12.0
ARG CUDA_VERSION=13.0
ARG CUDNN_VERSION=9

# This image is based on the latest official PyTorch image, because it already contains CUDA, CuDNN, and PyTorch
FROM pytorch/pytorch:${PYTORCH_VERSION}-cuda${CUDA_VERSION}-cudnn${CUDNN_VERSION}-runtime

# Defines build arguments for the versions of ComfyUI and ComfyUI Manager to use
ARG COMFYUI_VERSION=0.8.2
ARG COMFYUI_MANAGER_VERSION=4.0.5
ARG COMFYUI_VERSION=0.22.0

# Installs Git, because ComfyUI and the ComfyUI Manager are installed by cloning their respective Git repositories
RUN apt-get update --assume-yes && \
apt-get install --assume-yes \
git \
sudo \
libgl1-mesa-glx \
libgl1 \
libglx-mesa0 \
libglib2.0-0 && \
rm -rf /var/cache/apt/archives /var/lib/apt/lists/*

Expand All @@ -25,20 +25,12 @@ RUN git clone https://github.com/Comfy-Org/ComfyUI.git /opt/comfyui && \
cd /opt/comfyui && \
git checkout "v${COMFYUI_VERSION}"

# Clones the ComfyUI Manager repository and checks out the latest release; ComfyUI Manager is an extension for ComfyUI that enables users to install
# custom nodes and download models directly from the ComfyUI interface; instead of installing it to "/opt/comfyui/custom_nodes/ComfyUI-Manager", which
# 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
# 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
# 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
# removed; this way, the custom nodes are installed on the host machine
RUN git clone https://github.com/Comfy-Org/ComfyUI-Manager.git /opt/comfyui-manager && \
cd /opt/comfyui-manager && \
git checkout ${COMFYUI_MANAGER_VERSION}
# Removed ComfyUI Manager since it's now bundled with ComfyUI.

# Installs the required Python packages for both ComfyUI and the ComfyUI Manager
RUN pip install \
RUN pip install --break-system-packages \
--requirement /opt/comfyui/requirements.txt \
--requirement /opt/comfyui-manager/requirements.txt
--requirement /opt/comfyui/manager_requirements.txt

# Sets the working directory to the ComfyUI directory
WORKDIR /opt/comfyui
Expand Down
34 changes: 16 additions & 18 deletions source/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# Creates the directories for the models inside of the volume that is mounted from the host
echo "Creating directories for models..."
MODEL_DIRECTORIES=(
"audio_encoders"
"background_removal"
"checkpoints"
"clip"
"clip_vision"
Expand All @@ -11,9 +13,14 @@ MODEL_DIRECTORIES=(
"diffusers"
"diffusion_models"
"embeddings"
"frame_interpolation"
"geometry_estimation"
"gligen"
"hypernetworks"
"latent_upscale_models"
"loras"
"model_patches"
"optical_flow"
"photomaker"
"style_models"
"text_encoders"
Expand All @@ -26,27 +33,17 @@ for MODEL_DIRECTORY in ${MODEL_DIRECTORIES[@]}; do
mkdir -p /opt/comfyui/models/$MODEL_DIRECTORY
done

# Creates the symlink for the ComfyUI Manager to the custom nodes directory, which is also mounted from the host
echo "Creating symlink for ComfyUI Manager..."
rm --force /opt/comfyui/custom_nodes/ComfyUI-Manager
ln -s \
/opt/comfyui-manager \
/opt/comfyui/custom_nodes/ComfyUI-Manager

# The custom nodes that were installed using the ComfyUI Manager may have requirements of their own, which are not installed when the container is
# started for the first time; this loops over all custom nodes and installs the requirements of each custom node
echo "Installing requirements for custom nodes..."
for CUSTOM_NODE_DIRECTORY in /opt/comfyui/custom_nodes/*;
do
if [ "$CUSTOM_NODE_DIRECTORY" != "/opt/comfyui/custom_nodes/ComfyUI-Manager" ];
if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ];
then
if [ -f "$CUSTOM_NODE_DIRECTORY/requirements.txt" ];
then
CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/}
CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ }
echo "Installing requirements for $CUSTOM_NODE_NAME..."
pip install --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt"
fi
CUSTOM_NODE_NAME=${CUSTOM_NODE_DIRECTORY##*/}
CUSTOM_NODE_NAME=${CUSTOM_NODE_NAME//[-_]/ }
echo "Installing requirements for $CUSTOM_NODE_NAME..."
pip install --break-system-packages --requirement "$CUSTOM_NODE_DIRECTORY/requirements.txt"
fi
done

Expand All @@ -62,7 +59,8 @@ done
if [ -z "$USER_ID" ] || [ -z "$GROUP_ID" ];
then
echo "Running container as $USER..."
exec /opt/conda/bin/python main.py \
exec python main.py \
--enable-manager \
--port 8188 \
--listen 0.0.0.0 \
--disable-auto-launch \
Expand All @@ -72,12 +70,12 @@ else
getent group $GROUP_ID > /dev/null 2>&1 || groupadd --gid $GROUP_ID comfyui-user
id -u $USER_ID > /dev/null 2>&1 || useradd --uid $USER_ID --gid $GROUP_ID --create-home comfyui-user
chown --recursive $USER_ID:$GROUP_ID /opt/comfyui
chown --recursive $USER_ID:$GROUP_ID /opt/comfyui-manager
export PATH=$PATH:/home/comfyui-user/.local/bin

echo "Running container as comfyui-user ($USER_ID:$GROUP_ID)..."
sudo --set-home --preserve-env=PATH --user \#$USER_ID \
/opt/conda/bin/python main.py \
python main.py \
--enable-manager \
--port 8188 \
--listen 0.0.0.0 \
--disable-auto-launch \
Expand Down