From 154fbbd68142280aea48f69e83c7fded841e22de Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 01:22:16 -0400 Subject: [PATCH 01/16] Add Docker build script, Dockerfile, and Docker Compose setup for GPU compatibility --- Dockerfile | 53 ++++++++++++++++++++++++++++++++++++++++++++++ docker-build.sh | 26 +++++++++++++++++++++++ docker-compose.yml | 23 ++++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 Dockerfile create mode 100644 docker-build.sh create mode 100644 docker-compose.yml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..6793ad0e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,53 @@ +FROM nvidia/cuda:12.1.0-base-ubuntu20.04 AS base +ENV DEBIAN_FRONTEND=noninteractive + +# Install necessary dependencies and Python 3.12 +RUN apt-get update \ + && apt-get install -y \ + git \ + software-properties-common \ + curl \ + && add-apt-repository ppa:deadsnakes/ppa \ + && apt-get update \ + && apt-get install -y \ + python3.12 \ + python3.12-dev \ + python3.12-venv \ + python3-setuptools \ + wget \ + ffmpeg \ + libsm6 \ + libxext6 \ + libgl1 \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* + +# Install pip for Python 3.12 explicitly +RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ + && python3.12 get-pip.py \ + && rm get-pip.py + +# Set Python 3.12 as the default python3 and pip +RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \ + && update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3 1 + +# Set the working directory +WORKDIR /app + +# Clone the ComfyUI repository into the working directory +RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/comfyui + +# Install backend dependencies +RUN python3 -m venv /app/venv +RUN . venv/bin/activate && pip install --upgrade pip +RUN . venv/bin/activate && pip install pyyaml +RUN . venv/bin/activate && pip install -r /app/comfyui/requirements.txt + +# Install PyTorch with CUDA 12.1 support +RUN . venv/bin/activate && pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 + +# Expose the backend port +EXPOSE 8188 + +# Set the entrypoint command to activate the virtual environment and run the script +CMD ["/bin/bash", "-c", "source /app/venv/bin/activate && python3 /app/comfyui/main.py --listen 0.0.0.0 --port 8188 && echo 'Server started and ready to accept requests'"] diff --git a/docker-build.sh b/docker-build.sh new file mode 100644 index 00000000..ff776d75 --- /dev/null +++ b/docker-build.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +# Check if Docker and Docker Compose are installed +if ! command -v docker &> /dev/null || ! command -v docker-compose &> /dev/null +then + echo "Docker or Docker Compose not found. Please install them before proceeding." + exit 1 +fi + +# Build and start the container +docker-compose up --build -d + +# Wait for the container logs to indicate it's ready (looking for the custom message) +container_name="comfyui-v1" +while ! docker logs "$container_name" 2>&1 | grep -q "Server started and ready to accept requests"; do + echo "Waiting for the container to be fully started..." + sleep 1 +done + +# Copy the 'venv' directory from the container to the host +docker cp "$container_name:/app/venv" ./data/venv + +# Optional: Stop the container after everything is set up +docker-compose down + +echo "The container is set up, and the virtual environment is ready at ./venv." diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..81b49d79 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +services: + comfyui_backend: + build: + context: . + dockerfile: Dockerfile + container_name: comfyui-red-docker + ports: + - "8188:8188" # Expose the backend API or server + volumes: + - ./venv:/app/venv # Mount the venv directory for persistence helps with downloading custom nodes's dependencies from ConfyUI-Manager + - ./input:/app/comfyui/input # Mount the input directory directly inside /app/comfyui + - ./models:/app/comfyui/models # Mount the models directory directly inside /app/comfyui + - ./output:/app/comfyui/output # Mount the output directory directly inside /app/comfyui + - ./custom_nodes:/app/comfyui/custom_nodes # Mount the custom nodes directory directly inside /app/comfyui + - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. + #- ./workflows:/app/comfyui/user/default/workflows + + environment: + - DISPLAY=${DISPLAY} # Optional, for X11 display forwarding (if you use it) + - NVIDIA_VISIBLE_DEVICES=all # Ensure NVIDIA GPU is available to the container + - NVIDIA_DRIVER_CAPABILITIES=all # For CUDA support + runtime: nvidia # Use the NVIDIA runtime for GPU support + restart: "no" #change to "always" if you want to restart the container \ No newline at end of file From 1ac7710b8d28a6a885b02526f8dd558cc06f8e8e Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 02:32:58 -0400 Subject: [PATCH 02/16] Update docker-build.sh and docker-compose.yml --- docker-build.sh | 25 ++++++++++++++++++------- docker-compose.yml | 3 ++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index ff776d75..9c2b6b8f 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -7,20 +7,31 @@ then exit 1 fi -# Build and start the container +# Step 1: Build and start the container without mounting the venv volume +echo "Building and starting the container to initialize the virtual environment..." docker-compose up --build -d # Wait for the container logs to indicate it's ready (looking for the custom message) -container_name="comfyui-v1" +container_name="comfyui-red-docker" while ! docker logs "$container_name" 2>&1 | grep -q "Server started and ready to accept requests"; do echo "Waiting for the container to be fully started..." - sleep 1 + sleep 20 done -# Copy the 'venv' directory from the container to the host -docker cp "$container_name:/app/venv" ./data/venv +# Step 2: Copy the 'venv' directory from the container to the host +echo "Copying the virtual environment from the container to the host..." +docker cp "$container_name:/app/venv" ./venv -# Optional: Stop the container after everything is set up +# Step 3: Stop the container +echo "Stopping the container..." docker-compose down -echo "The container is set up, and the virtual environment is ready at ./venv." +# Step 4: Update the Docker Compose file to mount the venv volume +echo "Updating Docker Compose file to mount the virtual environment..." +sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml + +# Step 5: Restart the container with the venv volume mounted +echo "Restarting the container with the virtual environment mounted..." +docker-compose up -d + +echo "Setup complete! The container is running with the virtual environment persisted at ./venv." \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 81b49d79..53813303 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,13 +7,14 @@ services: ports: - "8188:8188" # Expose the backend API or server volumes: - - ./venv:/app/venv # Mount the venv directory for persistence helps with downloading custom nodes's dependencies from ConfyUI-Manager - ./input:/app/comfyui/input # Mount the input directory directly inside /app/comfyui - ./models:/app/comfyui/models # Mount the models directory directly inside /app/comfyui - ./output:/app/comfyui/output # Mount the output directory directly inside /app/comfyui - ./custom_nodes:/app/comfyui/custom_nodes # Mount the custom nodes directory directly inside /app/comfyui - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. #- ./workflows:/app/comfyui/user/default/workflows + + # Mount the venv directory for persistence environment: - DISPLAY=${DISPLAY} # Optional, for X11 display forwarding (if you use it) From 1c6acbaf1f4fc9881ba180e48d58ba8f4f598805 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 02:42:10 -0400 Subject: [PATCH 03/16] Updated docker-build.sh to include error handling for venv cp and in docker-compose.yml added image name tag --- docker-build.sh | 4 ++-- docker-compose.yml | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index 9c2b6b8f..992d5a11 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -9,10 +9,10 @@ fi # Step 1: Build and start the container without mounting the venv volume echo "Building and starting the container to initialize the virtual environment..." -docker-compose up --build -d +COMPOSE_BAKE=true docker-compose up --build -d # Wait for the container logs to indicate it's ready (looking for the custom message) -container_name="comfyui-red-docker" +container_name="comfyui-red-container" while ! docker logs "$container_name" 2>&1 | grep -q "Server started and ready to accept requests"; do echo "Waiting for the container to be fully started..." sleep 20 diff --git a/docker-compose.yml b/docker-compose.yml index 53813303..a55310ed 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -3,7 +3,8 @@ services: build: context: . dockerfile: Dockerfile - container_name: comfyui-red-docker + image: comfyui-red-image + container_name: comfyui-red-container ports: - "8188:8188" # Expose the backend API or server volumes: From 974d0b1f1a09e78eaf477c2f491978dc07b5e73d Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 04:27:18 -0400 Subject: [PATCH 04/16] Added Confyui manager to dockerfile, made changes to .sh file to recieve message from main.py, add place holder for venv volume mount --- Dockerfile | 8 +++++ docker-build.sh | 78 +++++++++++++++++++++++++++++++++++++++------- docker-compose.yml | 5 +-- 3 files changed, 77 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6793ad0e..c78c0c2d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -46,6 +46,14 @@ RUN . venv/bin/activate && pip install -r /app/comfyui/requirements.txt # Install PyTorch with CUDA 12.1 support RUN . venv/bin/activate && pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 +# Clone the ComfyUI-manager repository into a temporary directory, move it, and clean up +RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager && \ + mv /app/temp/* /app/comfyui/custom_nodes/ && \ + rm -rf /app/temp + +# Install ComfyUI-manager dependencies +RUN . venv/bin/activate && pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt + # Expose the backend port EXPOSE 8188 diff --git a/docker-build.sh b/docker-build.sh index 992d5a11..5c20d985 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -7,31 +7,85 @@ then exit 1 fi -# Step 1: Build and start the container without mounting the venv volume -echo "Building and starting the container to initialize the virtual environment..." -COMPOSE_BAKE=true docker-compose up --build -d +# Step 1: Build the container without using cache +echo "Building the container to initialize the virtual environment..." +COMPOSE_BAKE=true docker-compose build --no-cache +if [ $? -eq 0 ]; then + echo "Build completed successfully." +else + echo "Build failed. Exiting." + exit 1 +fi + +# Step 2: Start the container without mounting the venv volume +echo "Starting the container..." +COMPOSE_BAKE=true docker-compose up -d +if [ $? -eq 0 ]; then + echo "Container started successfully." +else + echo "Failed to start the container. Exiting." + exit 1 +fi + +# Step 3: Stream Docker logs to the terminal +container_name="comfyui-red-container" +echo "Streaming Docker logs for container: $container_name..." +docker logs -f "$container_name" & +LOGS_PID=$! # Save the PID of the background process # Wait for the container logs to indicate it's ready (looking for the custom message) -container_name="comfyui-red-container" -while ! docker logs "$container_name" 2>&1 | grep -q "Server started and ready to accept requests"; do - echo "Waiting for the container to be fully started..." +echo "Waiting for the container to be fully started..." +while ! docker logs "$container_name" 2>&1 | grep -q "To see the GUI go to: http://0.0.0.0:8188"; do sleep 20 done -# Step 2: Copy the 'venv' directory from the container to the host -echo "Copying the virtual environment from the container to the host..." -docker cp "$container_name:/app/venv" ./venv +# Stop streaming logs (kill the background process) +kill $LOGS_PID +echo "Container is fully started." -# Step 3: Stop the container +# Step 4: Copy the 'venv' directory from the container to the host +echo "Checking if /app/venv exists in the container..." +if docker exec "$container_name" ls /app/venv; then + echo "Copying the virtual environment from the container to the host..." + if ! docker cp "$container_name:/app/venv" ./venv; then + echo "Failed to copy the virtual environment. Exiting." + exit 1 + else + echo "Virtual environment copied successfully." + fi +else + echo "/app/venv does not exist in the container. Exiting." + exit 1 +fi + +# Step 5: Stop the container echo "Stopping the container..." docker-compose down +if [ $? -eq 0 ]; then + echo "Container stopped successfully." +else + echo "Failed to stop the container. Exiting." + exit 1 +fi -# Step 4: Update the Docker Compose file to mount the venv volume +# Step 6: Update the Docker Compose file to mount the venv volume echo "Updating Docker Compose file to mount the virtual environment..." sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml +if [ $? -eq 0 ]; then + echo "Docker Compose file updated successfully." +else + echo "Failed to update Docker Compose file. Exiting." + exit 1 +fi -# Step 5: Restart the container with the venv volume mounted +# Step 7: Restart the container with the venv volume mounted echo "Restarting the container with the virtual environment mounted..." docker-compose up -d +if [ $? -eq 0 ]; then + echo "Container restarted successfully." +else + echo "Failed to restart the container. Exiting." + exit 1 +fi echo "Setup complete! The container is running with the virtual environment persisted at ./venv." \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a55310ed..be888196 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -15,8 +15,9 @@ services: - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. #- ./workflows:/app/comfyui/user/default/workflows - # Mount the venv directory for persistence - + # Mount the venv directory for persistence(automatically mounted with you run docker-build.sh) + + environment: - DISPLAY=${DISPLAY} # Optional, for X11 display forwarding (if you use it) - NVIDIA_VISIBLE_DEVICES=all # Ensure NVIDIA GPU is available to the container From 34b77380c277b3730f59f1f0226cd961ecb3dc29 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 06:26:59 -0400 Subject: [PATCH 05/16] Added ComfyUI-Manager support, made changes to .sh file to create volume for custom_nodes --- Dockerfile | 2 +- docker-build.sh | 29 ++++++++++++++++++++++------- docker-compose.yml | 5 +++-- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Dockerfile b/Dockerfile index c78c0c2d..52d1e210 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,4 +58,4 @@ RUN . venv/bin/activate && pip install -r /app/comfyui/custom_nodes/ComfyUI-Mana EXPOSE 8188 # Set the entrypoint command to activate the virtual environment and run the script -CMD ["/bin/bash", "-c", "source /app/venv/bin/activate && python3 /app/comfyui/main.py --listen 0.0.0.0 --port 8188 && echo 'Server started and ready to accept requests'"] +CMD ["/bin/bash", "-c", "source /app/venv/bin/activate && python3 /app/comfyui/main.py --listen 0.0.0.0 --port 8188"] diff --git a/docker-build.sh b/docker-build.sh index 5c20d985..cdffdb8b 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -58,6 +58,21 @@ else exit 1 fi +# Step 4: Copy the 'ComfyUI-Manager' directory from the container to the host +echo "Checking if /app/comfyui/custom_nodes/ComfyUI-Manager exists in the container..." +if docker exec "$container_name" ls /app/comfyui/custom_nodes/ComfyUI-Manager; then + echo "Copying the ComfyUI-Manager from the container to the host..." + if ! docker cp "$container_name:/app/comfyui/custom_nodes/ComfyUI-Manager" ./custom_nodes/ComfyUI-Manager; then + echo "Failed to copy the ComfyUI-Manager. Exiting." + exit 1 + else + echo "ComfyUI-Manager copied successfully." + fi +else + echo "/app/comfyui/custom_nodes/ComfyUI-Manager does not exist in the container. Exiting." + exit 1 +fi + # Step 5: Stop the container echo "Stopping the container..." docker-compose down @@ -72,20 +87,20 @@ fi echo "Updating Docker Compose file to mount the virtual environment..." sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml if [ $? -eq 0 ]; then - echo "Docker Compose file updated successfully." + echo "Docker Compose file updated to include venv." else echo "Failed to update Docker Compose file. Exiting." exit 1 fi -# Step 7: Restart the container with the venv volume mounted -echo "Restarting the container with the virtual environment mounted..." -docker-compose up -d +# Step 6: Update the Docker Compose file to mount the venv volume +echo "Updating Docker Compose file to mount the custom_nodes..." +sed -i '/# Mount the custom nodes directory directly inside/a \ \ \ \ \ \ - ./custom_nodes:/app/comfyui/custom_nodes' docker-compose.yml if [ $? -eq 0 ]; then - echo "Container restarted successfully." + echo "Docker Compose file updated to include custom_nodes." else - echo "Failed to restart the container. Exiting." + echo "Failed to update Docker Compose file. Exiting." exit 1 fi -echo "Setup complete! The container is running with the virtual environment persisted at ./venv." \ No newline at end of file +echo "Setup complete! you can use "docker-compose up" to start the container." \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index be888196..34b9b715 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,11 +11,12 @@ services: - ./input:/app/comfyui/input # Mount the input directory directly inside /app/comfyui - ./models:/app/comfyui/models # Mount the models directory directly inside /app/comfyui - ./output:/app/comfyui/output # Mount the output directory directly inside /app/comfyui - - ./custom_nodes:/app/comfyui/custom_nodes # Mount the custom nodes directory directly inside /app/comfyui - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. #- ./workflows:/app/comfyui/user/default/workflows - # Mount the venv directory for persistence(automatically mounted with you run docker-build.sh) + # Mount the venv directory for persistence (automatically mounted with you run docker-build.sh) + + # Mount the custom nodes directory directly inside /app/comfyui (automatically mounted with you run docker-build.sh) environment: From 13a79662f4863248473d1d746faadfb1abc669d6 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 07:23:16 -0400 Subject: [PATCH 06/16] Final changes have been made need to update Readme --- docker-build.sh | 16 +++++++++------- docker-compose.yml | 14 +++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/docker-build.sh b/docker-build.sh index cdffdb8b..c3ca5579 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -17,7 +17,7 @@ else exit 1 fi -# Step 2: Start the container without mounting the venv volume +# Step 2: Start the container without mounting the volumes (venv, custom_nodes) echo "Starting the container..." COMPOSE_BAKE=true docker-compose up -d if [ $? -eq 0 ]; then @@ -36,14 +36,14 @@ LOGS_PID=$! # Save the PID of the background process # Wait for the container logs to indicate it's ready (looking for the custom message) echo "Waiting for the container to be fully started..." while ! docker logs "$container_name" 2>&1 | grep -q "To see the GUI go to: http://0.0.0.0:8188"; do - sleep 20 + sleep 10 done # Stop streaming logs (kill the background process) kill $LOGS_PID echo "Container is fully started." -# Step 4: Copy the 'venv' directory from the container to the host +# Step 4.1: Copy the 'venv' directory from the container to the host echo "Checking if /app/venv exists in the container..." if docker exec "$container_name" ls /app/venv; then echo "Copying the virtual environment from the container to the host..." @@ -58,7 +58,7 @@ else exit 1 fi -# Step 4: Copy the 'ComfyUI-Manager' directory from the container to the host +# Step 4.2: Copy the 'ComfyUI-Manager' directory from the container to the host echo "Checking if /app/comfyui/custom_nodes/ComfyUI-Manager exists in the container..." if docker exec "$container_name" ls /app/comfyui/custom_nodes/ComfyUI-Manager; then echo "Copying the ComfyUI-Manager from the container to the host..." @@ -83,7 +83,7 @@ else exit 1 fi -# Step 6: Update the Docker Compose file to mount the venv volume +# Step 6.1: Update the Docker Compose file to mount the venv volume echo "Updating Docker Compose file to mount the virtual environment..." sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml if [ $? -eq 0 ]; then @@ -93,7 +93,7 @@ else exit 1 fi -# Step 6: Update the Docker Compose file to mount the venv volume +# Step 6.2: Update the Docker Compose file to mount the venv volume echo "Updating Docker Compose file to mount the custom_nodes..." sed -i '/# Mount the custom nodes directory directly inside/a \ \ \ \ \ \ - ./custom_nodes:/app/comfyui/custom_nodes' docker-compose.yml if [ $? -eq 0 ]; then @@ -103,4 +103,6 @@ else exit 1 fi -echo "Setup complete! you can use "docker-compose up" to start the container." \ No newline at end of file +echo "======================================== SETUP COMPLETE ========================================" +echo "use 'docker-compose up' to start the container and 'docker-compose down' to stop the container." +echo "================================================================================================" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 34b9b715..fe46b96a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,15 +8,15 @@ services: ports: - "8188:8188" # Expose the backend API or server volumes: - - ./input:/app/comfyui/input # Mount the input directory directly inside /app/comfyui - - ./models:/app/comfyui/models # Mount the models directory directly inside /app/comfyui - - ./output:/app/comfyui/output # Mount the output directory directly inside /app/comfyui - - ./user:/app/comfyui/user # Comment this line and uncomment the next line if you want to have a workflows directory in the root directory. - #- ./workflows:/app/comfyui/user/default/workflows + - ./input:/app/comfyui/input # Volume for input files + - ./models:/app/comfyui/models # Volume for models + - ./output:/app/comfyui/output # Volume for output files + - ./user:/app/comfyui/user # Volume for user settings, Also this is where your workflows are stored + #- ./workflows:/app/comfyui/user/default/workflows # Uncomment if you to make a workflow directory in the comfyui directory - # Mount the venv directory for persistence (automatically mounted with you run docker-build.sh) + # Mount the venv directory for persistence (automatically mounted with you run docker-build.sh) #Don't change this - # Mount the custom nodes directory directly inside /app/comfyui (automatically mounted with you run docker-build.sh) + # Mount the custom nodes directory directly inside /app/comfyui (automatically mounted with you run docker-build.sh) #Don't change this environment: From 81d232e4b1bd976ea232f4219209a4819989b0a3 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 08:49:47 -0400 Subject: [PATCH 07/16] Changed the base image to cuda:12.6.3-cudnn-runtime-ubuntu24.04 and made sure everything works --- Dockerfile | 46 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52d1e210..087c984c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM nvidia/cuda:12.1.0-base-ubuntu20.04 AS base +FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base ENV DEBIAN_FRONTEND=noninteractive # Install necessary dependencies and Python 3.12 @@ -7,9 +7,6 @@ RUN apt-get update \ git \ software-properties-common \ curl \ - && add-apt-repository ppa:deadsnakes/ppa \ - && apt-get update \ - && apt-get install -y \ python3.12 \ python3.12-dev \ python3.12-venv \ @@ -22,40 +19,27 @@ RUN apt-get update \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* -# Install pip for Python 3.12 explicitly -RUN curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py \ - && python3.12 get-pip.py \ - && rm get-pip.py - -# Set Python 3.12 as the default python3 and pip -RUN update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 \ - && update-alternatives --install /usr/bin/pip pip /usr/local/bin/pip3 1 - # Set the working directory WORKDIR /app -# Clone the ComfyUI repository into the working directory -RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/comfyui +# Clone the ComfyUI repository and set up virtual environment +RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/comfyui \ + && python3.12 -m venv /app/venv \ + && /app/venv/bin/pip install --upgrade pip \ + && /app/venv/bin/pip install pyyaml \ + && /app/venv/bin/pip install -r /app/comfyui/requirements.txt -# Install backend dependencies -RUN python3 -m venv /app/venv -RUN . venv/bin/activate && pip install --upgrade pip -RUN . venv/bin/activate && pip install pyyaml -RUN . venv/bin/activate && pip install -r /app/comfyui/requirements.txt +# Install PyTorch with CUDA 12.6 support (stable version) +RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 -# Install PyTorch with CUDA 12.1 support -RUN . venv/bin/activate && pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121 - -# Clone the ComfyUI-manager repository into a temporary directory, move it, and clean up -RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager && \ - mv /app/temp/* /app/comfyui/custom_nodes/ && \ - rm -rf /app/temp - -# Install ComfyUI-manager dependencies -RUN . venv/bin/activate && pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt +# Clone ComfyUI-Manager and install its dependencies +RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager \ + && mv /app/temp/* /app/comfyui/custom_nodes/ \ + && rm -rf /app/temp \ + && /app/venv/bin/pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt # Expose the backend port EXPOSE 8188 -# Set the entrypoint command to activate the virtual environment and run the script +# Set the entrypoint to run the app CMD ["/bin/bash", "-c", "source /app/venv/bin/activate && python3 /app/comfyui/main.py --listen 0.0.0.0 --port 8188"] From b9c927d3516419f4f5b3849d19a0d207acc1ba45 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Sat, 15 Mar 2025 10:22:42 -0400 Subject: [PATCH 08/16] Added ReadMe section for docker nvidia --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index a807ea9d..c8fc6037 100644 --- a/README.md +++ b/README.md @@ -235,6 +235,24 @@ Install the dependencies by opening your terminal inside the ComfyUI folder and: After this you should have everything installed and can proceed to running ComfyUI. +### DOCKER - NVIDIA + +This uses the base image nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 and stable torch version from https://download.pytorch.org/whl/cu126. + +After cloning the repo, run the following command once in bash terminal to build the docker image: + +```chmod +x docker-build.sh``` + +```./docker-build.sh``` + +After you docker image is built, you can launch ComfyUI by running the following command: + +```docker-compose up``` + +To stop the container, run: + +```docker-compose down``` + ### Others: #### Apple Mac silicon From a52ecc6ea5374eb4213e1f2aa564f624edc2b033 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Mon, 17 Mar 2025 06:48:58 -0400 Subject: [PATCH 09/16] changed dockerfile to include amd's gpu and pytorch ver. --- Dockerfile | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index 087c984c..cb3b88e4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,18 @@ +# Nvidia GPU Base Images +# For NVIDIA GPU with stable CUDA version FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base + +# For NVIDIA GPU with latest CUDA version +FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base + +# AMD GPU Base Images +# For AMD GPU with stable ROCm version +FROM rocm/dev-ubuntu-24.04:6.2.4-complete AS base + +# For AMD GPU with latest ROCm version +FROM rocm/dev-ubuntu-24.04:6.3.4-complete AS base + +# Environment variables ENV DEBIAN_FRONTEND=noninteractive # Install necessary dependencies and Python 3.12 @@ -29,15 +43,26 @@ RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/comfyui \ && /app/venv/bin/pip install pyyaml \ && /app/venv/bin/pip install -r /app/comfyui/requirements.txt -# Install PyTorch with CUDA 12.6 support (stable version) -RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 - # Clone ComfyUI-Manager and install its dependencies RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager \ && mv /app/temp/* /app/comfyui/custom_nodes/ \ && rm -rf /app/temp \ && /app/venv/bin/pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt +# NVIDIA GPU PyTorch Installation + # Install PyTorch with CUDA 12.6 support (stable version) +RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 + + # Install PyTorch with CUDA 12.8 support (latest version) +RUN /app/venv/bin/pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128 + +# AMD GPU PyTorch Installation + # Install PyTorch with ROCm 6.2 support (stable version) +RUN /app/venv/bin/pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4 + # Install PyTorch with ROCm 6.3 support (latest version) +RUN /app/venv/bin/pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3 + + # Expose the backend port EXPOSE 8188 From 02290288095bd04a6cf62cd0aa57dc9ecfa7785e Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Mon, 17 Mar 2025 07:27:09 -0400 Subject: [PATCH 10/16] updated .sh to make the build more interactive and also worked out the docker file bugs --- Dockerfile | 23 ++++++---- docker-build.sh | 120 ++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 129 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index cb3b88e4..fc627558 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,16 @@ # Nvidia GPU Base Images # For NVIDIA GPU with stable CUDA version -FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base +# FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base # For NVIDIA GPU with latest CUDA version -FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base +# FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base # AMD GPU Base Images # For AMD GPU with stable ROCm version -FROM rocm/dev-ubuntu-24.04:6.2.4-complete AS base +# FROM rocm/dev-ubuntu-24.04:6.2.4-complete AS base # For AMD GPU with latest ROCm version -FROM rocm/dev-ubuntu-24.04:6.3.4-complete AS base +# FROM rocm/dev-ubuntu-24.04:6.3.4-complete AS base # Environment variables ENV DEBIAN_FRONTEND=noninteractive @@ -49,18 +49,21 @@ RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI- && rm -rf /app/temp \ && /app/venv/bin/pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt -# NVIDIA GPU PyTorch Installation + # NVIDIA GPU PyTorch Installation + # Install PyTorch with CUDA 12.6 support (stable version) -RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 +# RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 # Install PyTorch with CUDA 12.8 support (latest version) -RUN /app/venv/bin/pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128 +# RUN /app/venv/bin/pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128 + + # AMD GPU PyTorch Installation -# AMD GPU PyTorch Installation # Install PyTorch with ROCm 6.2 support (stable version) -RUN /app/venv/bin/pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4 +# RUN /app/venv/bin/pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4 + # Install PyTorch with ROCm 6.3 support (latest version) -RUN /app/venv/bin/pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3 +# RUN /app/venv/bin/pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3 # Expose the backend port diff --git a/docker-build.sh b/docker-build.sh index c3ca5579..385e3112 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -1,8 +1,120 @@ #!/bin/bash +# Backup the original Dockerfile +BACKUP_FILE="Dockerfile.bak" +cp Dockerfile "$BACKUP_FILE" + +# Function to restore the Dockerfile +restore_dockerfile() { + echo "Restoring Dockerfile to its original state..." + mv "$BACKUP_FILE" Dockerfile + echo "Dockerfile restored." +} + +# Set up trap to restore Dockerfile on script exit (success or failure) +trap restore_dockerfile EXIT + +# Function to display version information +display_version_info() { + echo "===========================================================" + echo "Stable Version:" + echo " - This is the latest stable version released by PyTorch." + echo " - It is thoroughly tested and recommended for deployment." + echo " - Pros: Reliable, well-tested, fewer bugs." + echo " - Cons: May not include the latest features or optimizations." + echo "" + echo "Latest Version:" + echo " - This is the latest development version of PyTorch." + echo " - It includes the newest features and optimizations but may have bugs." + echo " - Pros: Cutting-edge features, performance improvements." + echo " - Cons: Less stable, potential for encountering bugs." + echo "===========================================================" +} + +# Function to ask user for GPU type +ask_gpu_type() { + echo "What GPU do you have?" + select gpu in "NVIDIA" "AMD"; do + case $gpu in + NVIDIA) + echo "You selected NVIDIA." + break + ;; + AMD) + echo "You selected AMD." + break + ;; + *) + echo "Invalid option. Please choose 1 or 2." + ;; + esac + done +} + +# Function to ask user for version preference +ask_version() { + echo "Which version would you like to use?" + select version in "Stable" "Latest"; do + case $version in + Stable) + echo "You selected Stable." + break + ;; + Latest) + echo "You selected Latest." + break + ;; + *) + echo "Invalid option. Please choose 1 or 2." + ;; + esac + done +} + +# Display version information +display_version_info + +# Ask user for GPU type and version +ask_gpu_type +ask_version + +# Set base image and PyTorch installation command based on user input +if [[ "$gpu" == "NVIDIA" ]]; then + if [[ "$version" == "Stable" ]]; then + BASE_IMAGE="nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04" + TORCH_INSTALL="pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126" + # Uncomment the stable NVIDIA FROM line + sed -i '/# FROM nvidia\/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base/s/^# //' Dockerfile + # Uncomment the stable NVIDIA PyTorch installation line + sed -i '/# RUN \/app\/venv\/bin\/pip install torch torchvision torchaudio --extra-index-url https:\/\/download.pytorch.org\/whl\/cu126/s/^# //' Dockerfile + else + BASE_IMAGE="nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04" + TORCH_INSTALL="pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128" + # Uncomment the latest NVIDIA FROM line + sed -i '/# FROM nvidia\/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base/s/^# //' Dockerfile + # Uncomment the latest NVIDIA PyTorch installation line + sed -i '/# RUN \/app\/venv\/bin\/pip install --pre torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/nightly\/cu128/s/^# //' Dockerfile + fi +else + if [[ "$version" == "Stable" ]]; then + BASE_IMAGE="rocm/dev-ubuntu-24.04:6.2.4-complete" + TORCH_INSTALL="pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4" + # Uncomment the stable AMD FROM line + sed -i '/# FROM rocm\/dev-ubuntu-24.04:6.2.4-complete AS base/s/^# //' Dockerfile + # Uncomment the stable AMD PyTorch installation line + sed -i '/# RUN \/app\/venv\/bin\/pip install torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/rocm6.2.4/s/^# //' Dockerfile + else + BASE_IMAGE="rocm/dev-ubuntu-24.04:6.3.4-complete" + TORCH_INSTALL="pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3" + # Uncomment the latest AMD FROM line + sed -i '/# FROM rocm\/dev-ubuntu-24.04:6.3.4-complete AS base/s/^# //' Dockerfile + # Uncomment the latest AMD PyTorch installation line + sed -i '/# RUN \/app\/venv\/bin\/pip3 install --pre torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/nightly\/rocm6.3/s/^# //' Dockerfile + fi +fi + # Check if Docker and Docker Compose are installed -if ! command -v docker &> /dev/null || ! command -v docker-compose &> /dev/null -then +if ! command -v docker &> /dev/null || ! command -v docker-compose &> /dev/null; then echo "Docker or Docker Compose not found. Please install them before proceeding." exit 1 fi @@ -17,7 +129,7 @@ else exit 1 fi -# Step 2: Start the container without mounting the volumes (venv, custom_nodes) +# Step 2: Start the container without mounting the volumes (venv, custom_nodes) echo "Starting the container..." COMPOSE_BAKE=true docker-compose up -d if [ $? -eq 0 ]; then @@ -93,7 +205,7 @@ else exit 1 fi -# Step 6.2: Update the Docker Compose file to mount the venv volume +# Step 6.2: Update the Docker Compose file to mount the custom_nodes volume echo "Updating Docker Compose file to mount the custom_nodes..." sed -i '/# Mount the custom nodes directory directly inside/a \ \ \ \ \ \ - ./custom_nodes:/app/comfyui/custom_nodes' docker-compose.yml if [ $? -eq 0 ]; then From e4050bc80952792a9e65f3c584fc3d180ab08293 Mon Sep 17 00:00:00 2001 From: RedsAnalysis Date: Mon, 17 Mar 2025 12:49:32 -0400 Subject: [PATCH 11/16] Made changes to README --- README.md | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c8fc6037..164cb943 100644 --- a/README.md +++ b/README.md @@ -235,24 +235,6 @@ Install the dependencies by opening your terminal inside the ComfyUI folder and: After this you should have everything installed and can proceed to running ComfyUI. -### DOCKER - NVIDIA - -This uses the base image nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 and stable torch version from https://download.pytorch.org/whl/cu126. - -After cloning the repo, run the following command once in bash terminal to build the docker image: - -```chmod +x docker-build.sh``` - -```./docker-build.sh``` - -After you docker image is built, you can launch ComfyUI by running the following command: - -```docker-compose up``` - -To stop the container, run: - -```docker-compose down``` - ### Others: #### Apple Mac silicon @@ -287,6 +269,28 @@ For models compatible with Cambricon Extension for PyTorch (torch_mlu). Here's a 2. Next, install the PyTorch(torch_mlu) following the instructions on the [Installation](https://www.cambricon.com/docs/sdk_1.15.0/cambricon_pytorch_1.17.0/user_guide_1.9/index.html) 3. Launch ComfyUI by running `python main.py` +### DOCKER + +This uses the base image nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 and stable torch version from https://download.pytorch.org/whl/cu126. + +After cloning the repo, run the following command once in bash terminal to build the docker image: + +```chmod +x docker-build.sh``` + +```./docker-build.sh``` + +It will prompt you to select you GPU and the pytorch version you want to install. PS use latest for RTX 5000 seriers cards. + +Use ``` 1 or 2 ```, to make your selection. + +After you docker image is built, you can launch ComfyUI by running the following command: + +```docker-compose up``` + +To stop the container, run: + +```docker-compose down``` + # Running ```python main.py``` From ab866279c8dc31466bdbc51bfe82bacd77b5b6cb Mon Sep 17 00:00:00 2001 From: Red Date: Mon, 17 Mar 2025 12:50:46 -0400 Subject: [PATCH 12/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 164cb943..eaff9c4a 100644 --- a/README.md +++ b/README.md @@ -269,7 +269,7 @@ For models compatible with Cambricon Extension for PyTorch (torch_mlu). Here's a 2. Next, install the PyTorch(torch_mlu) following the instructions on the [Installation](https://www.cambricon.com/docs/sdk_1.15.0/cambricon_pytorch_1.17.0/user_guide_1.9/index.html) 3. Launch ComfyUI by running `python main.py` -### DOCKER +# DOCKER This uses the base image nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 and stable torch version from https://download.pytorch.org/whl/cu126. From 19edb4f8a21619f30e263a11ff4f36d02dda6c5a Mon Sep 17 00:00:00 2001 From: Red Date: Mon, 17 Mar 2025 12:53:32 -0400 Subject: [PATCH 13/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index eaff9c4a..7007757c 100644 --- a/README.md +++ b/README.md @@ -271,7 +271,7 @@ For models compatible with Cambricon Extension for PyTorch (torch_mlu). Here's a # DOCKER -This uses the base image nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 and stable torch version from https://download.pytorch.org/whl/cu126. +FOR Nvidia and AMD supported by ROCm After cloning the repo, run the following command once in bash terminal to build the docker image: From b60e5748f2ab5a29e5a59031d83cd2eb8ca0f590 Mon Sep 17 00:00:00 2001 From: Red Date: Sun, 6 Apr 2025 03:16:18 -0400 Subject: [PATCH 14/16] Update requirements.txt to remove torch as we are installing the nightly version redundant installation as it will be overwritten by nightly install in the next layer. --- requirements.txt | 3 --- 1 file changed, 3 deletions(-) diff --git a/requirements.txt b/requirements.txt index 806fbc75..404056ef 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,8 +1,5 @@ comfyui-frontend-package==1.14.6 -torch torchsde -torchvision -torchaudio numpy>=1.25.0 einops transformers>=4.28.1 From d40d7c38e4fdc4bcc8787b46b50520a5f753a318 Mon Sep 17 00:00:00 2001 From: Arambhumi Reddy Date: Sun, 6 Apr 2025 10:52:25 -0400 Subject: [PATCH 15/16] modified docker from file change to ARG, added health check and modified volume to use named volume also added uv to make the build faster --- Dockerfile | 166 +++++++++++++++------------ docker-build.sh | 273 +++++++++++++++++---------------------------- docker-compose.yml | 53 +++++---- 3 files changed, 232 insertions(+), 260 deletions(-) diff --git a/Dockerfile b/Dockerfile index fc627558..f906f361 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,73 +1,97 @@ -# Nvidia GPU Base Images -# For NVIDIA GPU with stable CUDA version -# FROM nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base +# --- Base Image Selection --- + ARG BASE_IMAGE_TAG="nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04" + ARG TORCH_PRE_FLAG="" + ARG TORCH_INDEX_URL="" + ARG TORCH_EXTRA_INDEX_URL="" + + # Use the ARG for the base image build stage + FROM ${BASE_IMAGE_TAG} AS base + # --- First stage ends here --- + + # --- Start the final stage from the base --- + FROM base + + # Environment variables (Keep as is) + ENV DEBIAN_FRONTEND=noninteractive + ENV UV_INSTALL_DIR="/root/.local/bin" + ENV UV_EXE="/root/.local/bin/uv" + ENV PYTHON_VERSION="3.12" + ENV VENV_PATH="/app/venv" + ENV VENV_PYTHON="${VENV_PATH}/bin/python" + ENV PATH="${VENV_PATH}/bin:${UV_INSTALL_DIR}:${PATH}" + + # --- Layer 1: Install OS Dependencies & Python --- (Keep as is) + RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + git curl "python${PYTHON_VERSION}" "python${PYTHON_VERSION}-dev" "python${PYTHON_VERSION}-venv" \ + wget ffmpeg libsm6 libxext6 libgl1 grep \ + && apt-get clean && rm -rf /var/lib/apt/lists/* + + # --- Layer 2: Install and Verify UV --- (Keep as is) + RUN echo "Installing uv..." \ + && curl -LsSf https://astral.sh/uv/install.sh | sh \ + && echo "Verifying uv installation..." \ + && ${UV_EXE} --version + + WORKDIR /app + + # --- Layer 3: Create Virtual Environment & Ensure Core Tools --- + RUN echo "Creating virtual environment with uv..." \ + && ${UV_EXE} venv ${VENV_PATH} --python "python${PYTHON_VERSION}" \ + && echo "Ensuring pip and wheel are installed/updated in venv..." \ + # Explicitly install/upgrade pip and wheel using uv right after venv creation + && ${UV_EXE} pip install -p ${VENV_PYTHON} --upgrade pip wheel \ + && echo "Verifying pip exists in venv:" \ + && ${VENV_PYTHON} -m pip --version -# For NVIDIA GPU with latest CUDA version -# FROM nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base +# --- RE-DECLARE ARGs HERE --- + ARG TORCH_PRE_FLAG + ARG TORCH_INDEX_URL + ARG TORCH_EXTRA_INDEX_URL -# AMD GPU Base Images -# For AMD GPU with stable ROCm version -# FROM rocm/dev-ubuntu-24.04:6.2.4-complete AS base - -# For AMD GPU with latest ROCm version -# FROM rocm/dev-ubuntu-24.04:6.3.4-complete AS base - -# Environment variables -ENV DEBIAN_FRONTEND=noninteractive - -# Install necessary dependencies and Python 3.12 -RUN apt-get update \ - && apt-get install -y \ - git \ - software-properties-common \ - curl \ - python3.12 \ - python3.12-dev \ - python3.12-venv \ - python3-setuptools \ - wget \ - ffmpeg \ - libsm6 \ - libxext6 \ - libgl1 \ - && apt-get clean \ - && rm -rf /var/lib/apt/lists/* - -# Set the working directory -WORKDIR /app - -# Clone the ComfyUI repository and set up virtual environment -RUN git clone https://github.com/comfyanonymous/ComfyUI.git /app/comfyui \ - && python3.12 -m venv /app/venv \ - && /app/venv/bin/pip install --upgrade pip \ - && /app/venv/bin/pip install pyyaml \ - && /app/venv/bin/pip install -r /app/comfyui/requirements.txt - -# Clone ComfyUI-Manager and install its dependencies -RUN git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/temp/ComfyUI-Manager \ - && mv /app/temp/* /app/comfyui/custom_nodes/ \ - && rm -rf /app/temp \ - && /app/venv/bin/pip install -r /app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt - - # NVIDIA GPU PyTorch Installation - - # Install PyTorch with CUDA 12.6 support (stable version) -# RUN /app/venv/bin/pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126 - - # Install PyTorch with CUDA 12.8 support (latest version) -# RUN /app/venv/bin/pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128 - - # AMD GPU PyTorch Installation - - # Install PyTorch with ROCm 6.2 support (stable version) -# RUN /app/venv/bin/pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4 - - # Install PyTorch with ROCm 6.3 support (latest version) -# RUN /app/venv/bin/pip3 install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3 - - -# Expose the backend port -EXPOSE 8188 - -# Set the entrypoint to run the app -CMD ["/bin/bash", "-c", "source /app/venv/bin/activate && python3 /app/comfyui/main.py --listen 0.0.0.0 --port 8188"] + # --- Layer 4: PyTorch Installation --- + RUN echo "--- Executing PyTorch Install Step ---" \ + && echo " ARG TORCH_PRE_FLAG='${TORCH_PRE_FLAG}'" \ + && echo " ARG TORCH_INDEX_URL='${TORCH_INDEX_URL}'" \ + && echo " ARG TORCH_EXTRA_INDEX_URL='${TORCH_EXTRA_INDEX_URL}'" \ + && echo " Now running uv pip install..." \ + && ${UV_EXE} pip install \ + --upgrade \ + -p ${VENV_PYTHON} \ + # --- REMOVED INNER QUOTES from expansions --- + ${TORCH_PRE_FLAG:+$TORCH_PRE_FLAG} \ + ${TORCH_INDEX_URL:+$TORCH_INDEX_URL} \ + ${TORCH_EXTRA_INDEX_URL:+$TORCH_EXTRA_INDEX_URL} \ + # --- END REMOVED INNER QUOTES --- + torch torchvision torchaudio + +# --- Layer 5: ComfyUI Setup (Clone & Requirements) --- + RUN echo "Cloning ComfyUI..." \ + && git clone https://github.com/RedsAnalysis/ComfyUI.git /app/comfyui \ + && echo "Filtering requirements.txt to remove potential torch conflicts..." \ + && grep -vE '^torch(vision|audio)?(=|<|>)?' /app/comfyui/requirements.txt > /app/comfyui/requirements.filtered.txt \ + && REQS_FILE="/app/comfyui/requirements.filtered.txt" \ + && echo "Installing ComfyUI base requirements from ${REQS_FILE}..." \ + # Explicitly add torchsde here along with requirements file + && ${UV_EXE} pip install \ + -p ${VENV_PYTHON} \ + pyyaml \ + torchsde \ + -r ${REQS_FILE} + + # --- Layer 6: ComfyUI-Manager Setup --- (Keep as is) + RUN echo "Cloning ComfyUI-Manager..." \ + && git clone https://github.com/ltdrdata/ComfyUI-Manager.git /app/comfyui/custom_nodes/ComfyUI-Manager \ + && MANAGER_REQS="/app/comfyui/custom_nodes/ComfyUI-Manager/requirements.txt" \ + && if [ -f "${MANAGER_REQS}" ]; then \ + echo "Installing ComfyUI-Manager requirements..."; \ + ${UV_EXE} pip install -p ${VENV_PYTHON} -r ${MANAGER_REQS}; \ + else \ + echo "ComfyUI-Manager requirements.txt not found."; \ + fi + + # --- Final Setup --- (Keep as is) + EXPOSE 8188 + HEALTHCHECK --interval=15s --timeout=5s --start-period=30s --retries=3 \ + CMD curl --fail http://localhost:8188/ || exit 1 + CMD ["python", "/app/comfyui/main.py", "--listen", "0.0.0.0", "--port", "8188"] \ No newline at end of file diff --git a/docker-build.sh b/docker-build.sh index 385e3112..c91d544a 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -1,51 +1,50 @@ #!/bin/bash -# Backup the original Dockerfile -BACKUP_FILE="Dockerfile.bak" -cp Dockerfile "$BACKUP_FILE" +set -e # Exit immediately if a command exits with a non-zero status. -# Function to restore the Dockerfile -restore_dockerfile() { - echo "Restoring Dockerfile to its original state..." - mv "$BACKUP_FILE" Dockerfile - echo "Dockerfile restored." -} - -# Set up trap to restore Dockerfile on script exit (success or failure) -trap restore_dockerfile EXIT +# Define Python Version and Venv Path (must match Dockerfile ENV) +PYTHON_VERSION="3.12" +VENV_PATH="/app/venv" +VENV_PYTHON="${VENV_PATH}/bin/python" # Used for constructing PyTorch install args # Function to display version information display_version_info() { echo "===========================================================" - echo "Stable Version:" - echo " - This is the latest stable version released by PyTorch." - echo " - It is thoroughly tested and recommended for deployment." - echo " - Pros: Reliable, well-tested, fewer bugs." - echo " - Cons: May not include the latest features or optimizations." - echo "" - echo "Latest Version:" - echo " - This is the latest development version of PyTorch." - echo " - It includes the newest features and optimizations but may have bugs." - echo " - Pros: Cutting-edge features, performance improvements." - echo " - Cons: Less stable, potential for encountering bugs." + echo " PyTorch Version Selection:" + echo "-----------------------------------------------------------" + echo " Stable Version:" + echo " - Thoroughly tested, recommended for general use." + echo " - Pros: Reliability, fewer bugs." + echo " - Cons: May lack the absolute latest features." + echo "-----------------------------------------------------------" + echo " Latest Version (Nightly/Pre-release):" + echo " - Includes newest features and optimizations." + echo " - Pros: Cutting-edge capabilities." + echo " - Cons: Potentially less stable, may have bugs." echo "===========================================================" } # Function to ask user for GPU type ask_gpu_type() { - echo "What GPU do you have?" - select gpu in "NVIDIA" "AMD"; do - case $gpu in + echo "Select GPU Type:" + select gpu_choice in "NVIDIA" "AMD" "Cancel"; do + case $gpu_choice in NVIDIA) - echo "You selected NVIDIA." + gpu="NVIDIA" + echo "Selected: NVIDIA" break ;; AMD) - echo "You selected AMD." + gpu="AMD" + echo "Selected: AMD" break ;; + Cancel) + echo "Build cancelled." + exit 0 + ;; *) - echo "Invalid option. Please choose 1 or 2." + echo "Invalid option $REPLY. Please choose 1, 2, or 3." ;; esac done @@ -53,168 +52,106 @@ ask_gpu_type() { # Function to ask user for version preference ask_version() { - echo "Which version would you like to use?" - select version in "Stable" "Latest"; do - case $version in + echo "Select PyTorch Version:" + select version_choice in "Stable" "Latest" "Cancel"; do + case $version_choice in Stable) - echo "You selected Stable." + version="Stable" + echo "Selected: Stable" break ;; Latest) - echo "You selected Latest." + version="Latest" + echo "Selected: Latest" break ;; + Cancel) + echo "Build cancelled." + exit 0 + ;; *) - echo "Invalid option. Please choose 1 or 2." + echo "Invalid option $REPLY. Please choose 1, 2, or 3." ;; esac done } -# Display version information +# --- Main Script Logic --- display_version_info - -# Ask user for GPU type and version ask_gpu_type ask_version -# Set base image and PyTorch installation command based on user input +# --- Determine Build Arguments based on Input --- +echo "Configuring build arguments..." + +# --- Initialize new ARGs --- +TORCH_PRE_FLAG="" +TORCH_INDEX_URL="" +TORCH_EXTRA_INDEX_URL="" # Initialize as empty + if [[ "$gpu" == "NVIDIA" ]]; then if [[ "$version" == "Stable" ]]; then - BASE_IMAGE="nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04" - TORCH_INSTALL="pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu126" - # Uncomment the stable NVIDIA FROM line - sed -i '/# FROM nvidia\/cuda:12.6.3-cudnn-runtime-ubuntu24.04 AS base/s/^# //' Dockerfile - # Uncomment the stable NVIDIA PyTorch installation line - sed -i '/# RUN \/app\/venv\/bin\/pip install torch torchvision torchaudio --extra-index-url https:\/\/download.pytorch.org\/whl\/cu126/s/^# //' Dockerfile - else - BASE_IMAGE="nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04" - TORCH_INSTALL="pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/cu128" - # Uncomment the latest NVIDIA FROM line - sed -i '/# FROM nvidia\/cuda:12.8.1-cudnn-runtime-ubuntu24.04 AS base/s/^# //' Dockerfile - # Uncomment the latest NVIDIA PyTorch installation line - sed -i '/# RUN \/app\/venv\/bin\/pip install --pre torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/nightly\/cu128/s/^# //' Dockerfile + BASE_IMAGE_TAG="nvidia/cuda:12.6.3-cudnn-runtime-ubuntu24.04" + TORCH_EXTRA_INDEX_URL="--extra-index-url https://download.pytorch.org/whl/cu126" + else # Latest + BASE_IMAGE_TAG="nvidia/cuda:12.8.1-cudnn-runtime-ubuntu24.04" + TORCH_PRE_FLAG="--pre" + TORCH_INDEX_URL="--index-url https://download.pytorch.org/whl/nightly/cu128" + fi + +elif [[ "$gpu" == "AMD" ]]; then + if [[ "$version" == "Stable" ]]; then + BASE_IMAGE_TAG="rocm/dev-ubuntu-24.04:6.2.4-complete" + TORCH_INDEX_URL="--index-url https://download.pytorch.org/whl/rocm6.2" + else # Latest + BASE_IMAGE_TAG="rocm/dev-ubuntu-24.04:6.3.4-complete" + TORCH_PRE_FLAG="--pre" + TORCH_INDEX_URL="--index-url https://download.pytorch.org/whl/nightly/rocm6.3" fi else - if [[ "$version" == "Stable" ]]; then - BASE_IMAGE="rocm/dev-ubuntu-24.04:6.2.4-complete" - TORCH_INSTALL="pip install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/rocm6.2.4" - # Uncomment the stable AMD FROM line - sed -i '/# FROM rocm\/dev-ubuntu-24.04:6.2.4-complete AS base/s/^# //' Dockerfile - # Uncomment the stable AMD PyTorch installation line - sed -i '/# RUN \/app\/venv\/bin\/pip install torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/rocm6.2.4/s/^# //' Dockerfile - else - BASE_IMAGE="rocm/dev-ubuntu-24.04:6.3.4-complete" - TORCH_INSTALL="pip install --pre torch torchvision torchaudio --index-url https://download.pytorch.org/whl/nightly/rocm6.3" - # Uncomment the latest AMD FROM line - sed -i '/# FROM rocm\/dev-ubuntu-24.04:6.3.4-complete AS base/s/^# //' Dockerfile - # Uncomment the latest AMD PyTorch installation line - sed -i '/# RUN \/app\/venv\/bin\/pip3 install --pre torch torchvision torchaudio --index-url https:\/\/download.pytorch.org\/whl\/nightly\/rocm6.3/s/^# //' Dockerfile - fi -fi - -# Check if Docker and Docker Compose are installed -if ! command -v docker &> /dev/null || ! command -v docker-compose &> /dev/null; then - echo "Docker or Docker Compose not found. Please install them before proceeding." + echo "Error: Invalid GPU type configured after selection." exit 1 fi -# Step 1: Build the container without using cache -echo "Building the container to initialize the virtual environment..." -COMPOSE_BAKE=true docker-compose build --no-cache -if [ $? -eq 0 ]; then - echo "Build completed successfully." +# --- Construct and Run the Docker Build Command --- +IMAGE_NAME="comfyui-red-image:${gpu,,}-${version,,}" + +echo "-----------------------------------------------------------" +echo "Starting Docker build..." +echo " Image Tag: ${IMAGE_NAME}" +echo " Base Image: ${BASE_IMAGE_TAG}" +echo " PyTorch Pre Flag: '${TORCH_PRE_FLAG}'" +echo " PyTorch Index URL: '${TORCH_INDEX_URL}'" +echo " PyTorch Extra Index URL: '${TORCH_EXTRA_INDEX_URL}'" +echo "-----------------------------------------------------------" + +# Build the image using the SEPARATE Docker build arguments +# REMOVED the interrupting comments from within this command block +docker build \ + --no-cache \ + --build-arg BASE_IMAGE_TAG="${BASE_IMAGE_TAG}" \ + --build-arg TORCH_PRE_FLAG="${TORCH_PRE_FLAG}" \ + --build-arg TORCH_INDEX_URL="${TORCH_INDEX_URL}" \ + --build-arg TORCH_EXTRA_INDEX_URL="${TORCH_EXTRA_INDEX_URL}" \ + -t "${IMAGE_NAME}" \ + -f Dockerfile . + +BUILD_STATUS=$? + +# --- Report Build Status --- +echo "-----------------------------------------------------------" +if [ $BUILD_STATUS -eq 0 ]; then + echo "Docker build successful!" + echo "Image created: ${IMAGE_NAME}" + echo "" + echo "To run the container using Docker Compose (assuming docker-compose.yml is configured):" + echo " docker-compose up -d" + echo "" + echo "To stop the container:" + echo " docker-compose down" else - echo "Build failed. Exiting." - exit 1 + echo "Docker build failed with status: ${BUILD_STATUS}" fi +echo "===========================================================" -# Step 2: Start the container without mounting the volumes (venv, custom_nodes) -echo "Starting the container..." -COMPOSE_BAKE=true docker-compose up -d -if [ $? -eq 0 ]; then - echo "Container started successfully." -else - echo "Failed to start the container. Exiting." - exit 1 -fi - -# Step 3: Stream Docker logs to the terminal -container_name="comfyui-red-container" -echo "Streaming Docker logs for container: $container_name..." -docker logs -f "$container_name" & -LOGS_PID=$! # Save the PID of the background process - -# Wait for the container logs to indicate it's ready (looking for the custom message) -echo "Waiting for the container to be fully started..." -while ! docker logs "$container_name" 2>&1 | grep -q "To see the GUI go to: http://0.0.0.0:8188"; do - sleep 10 -done - -# Stop streaming logs (kill the background process) -kill $LOGS_PID -echo "Container is fully started." - -# Step 4.1: Copy the 'venv' directory from the container to the host -echo "Checking if /app/venv exists in the container..." -if docker exec "$container_name" ls /app/venv; then - echo "Copying the virtual environment from the container to the host..." - if ! docker cp "$container_name:/app/venv" ./venv; then - echo "Failed to copy the virtual environment. Exiting." - exit 1 - else - echo "Virtual environment copied successfully." - fi -else - echo "/app/venv does not exist in the container. Exiting." - exit 1 -fi - -# Step 4.2: Copy the 'ComfyUI-Manager' directory from the container to the host -echo "Checking if /app/comfyui/custom_nodes/ComfyUI-Manager exists in the container..." -if docker exec "$container_name" ls /app/comfyui/custom_nodes/ComfyUI-Manager; then - echo "Copying the ComfyUI-Manager from the container to the host..." - if ! docker cp "$container_name:/app/comfyui/custom_nodes/ComfyUI-Manager" ./custom_nodes/ComfyUI-Manager; then - echo "Failed to copy the ComfyUI-Manager. Exiting." - exit 1 - else - echo "ComfyUI-Manager copied successfully." - fi -else - echo "/app/comfyui/custom_nodes/ComfyUI-Manager does not exist in the container. Exiting." - exit 1 -fi - -# Step 5: Stop the container -echo "Stopping the container..." -docker-compose down -if [ $? -eq 0 ]; then - echo "Container stopped successfully." -else - echo "Failed to stop the container. Exiting." - exit 1 -fi - -# Step 6.1: Update the Docker Compose file to mount the venv volume -echo "Updating Docker Compose file to mount the virtual environment..." -sed -i '/# Mount the venv directory for persistence/a \ \ \ \ \ \ - ./venv:/app/venv' docker-compose.yml -if [ $? -eq 0 ]; then - echo "Docker Compose file updated to include venv." -else - echo "Failed to update Docker Compose file. Exiting." - exit 1 -fi - -# Step 6.2: Update the Docker Compose file to mount the custom_nodes volume -echo "Updating Docker Compose file to mount the custom_nodes..." -sed -i '/# Mount the custom nodes directory directly inside/a \ \ \ \ \ \ - ./custom_nodes:/app/comfyui/custom_nodes' docker-compose.yml -if [ $? -eq 0 ]; then - echo "Docker Compose file updated to include custom_nodes." -else - echo "Failed to update Docker Compose file. Exiting." - exit 1 -fi - -echo "======================================== SETUP COMPLETE ========================================" -echo "use 'docker-compose up' to start the container and 'docker-compose down' to stop the container." -echo "================================================================================================" \ No newline at end of file +exit $BUILD_STATUS \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index fe46b96a..8519e477 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,27 +1,38 @@ services: comfyui_backend: - build: - context: . - dockerfile: Dockerfile - image: comfyui-red-image + image: comfyui-red-image:nvidia-latest # <-- ADJUST THIS TAG container_name: comfyui-red-container ports: - - "8188:8188" # Expose the backend API or server + - "8188:8188" volumes: - - ./input:/app/comfyui/input # Volume for input files - - ./models:/app/comfyui/models # Volume for models - - ./output:/app/comfyui/output # Volume for output files - - ./user:/app/comfyui/user # Volume for user settings, Also this is where your workflows are stored - #- ./workflows:/app/comfyui/user/default/workflows # Uncomment if you to make a workflow directory in the comfyui directory - - # Mount the venv directory for persistence (automatically mounted with you run docker-build.sh) #Don't change this - - # Mount the custom nodes directory directly inside /app/comfyui (automatically mounted with you run docker-build.sh) #Don't change this - - + # Host Mounts for data access + - ./input:/app/comfyui/input + - ./output:/app/comfyui/output + - ./models:/app/comfyui/models + # Named Volumes for persistent state + - comfyui_custom_nodes:/app/comfyui/custom_nodes + - comfyui_python_packages:/app/python_user_packages + - comfyui_user_config:/app/comfyui/user environment: - - DISPLAY=${DISPLAY} # Optional, for X11 display forwarding (if you use it) - - NVIDIA_VISIBLE_DEVICES=all # Ensure NVIDIA GPU is available to the container - - NVIDIA_DRIVER_CAPABILITIES=all # For CUDA support - runtime: nvidia # Use the NVIDIA runtime for GPU support - restart: "no" #change to "always" if you want to restart the container \ No newline at end of file + - PYTHONUSERBASE=/app/python_user_packages + - PATH=/app/python_user_packages/bin:/app/venv/bin:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + # - TZ=America/New_York + deploy: + resources: + reservations: + devices: + - driver: nvidia + count: all + capabilities: [gpu] + restart: unless-stopped + # Fallback GPU config (uncomment if 'deploy' fails) + # runtime: nvidia + # environment: + # - NVIDIA_VISIBLE_DEVICES=all + # - NVIDIA_DRIVER_CAPABILITIES=all + +# Named Volume Definitions +volumes: + comfyui_custom_nodes: {} + comfyui_python_packages: {} + comfyui_user_config: {} \ No newline at end of file From 9608d029c5a424ddf75b290a48b71bffe1fbd9b5 Mon Sep 17 00:00:00 2001 From: Arambhumi Reddy Date: Sun, 6 Apr 2025 11:28:42 -0400 Subject: [PATCH 16/16] changed the compose file to contain name volume for venv --- docker-compose.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8519e477..fdf4b0bd 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,6 +1,6 @@ services: comfyui_backend: - image: comfyui-red-image:nvidia-latest # <-- ADJUST THIS TAG + image: comfyui-red-image:nvidia-latest container_name: comfyui-red-container ports: - "8188:8188" @@ -10,13 +10,11 @@ services: - ./output:/app/comfyui/output - ./models:/app/comfyui/models # Named Volumes for persistent state + - comfyui_venv_data:/app/venv - comfyui_custom_nodes:/app/comfyui/custom_nodes - - comfyui_python_packages:/app/python_user_packages - comfyui_user_config:/app/comfyui/user environment: - - PYTHONUSERBASE=/app/python_user_packages - - PATH=/app/python_user_packages/bin:/app/venv/bin:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - # - TZ=America/New_York + - PATH=/app/venv/bin:/root/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin deploy: resources: reservations: @@ -33,6 +31,6 @@ services: # Named Volume Definitions volumes: + comfyui_venv_data: {} comfyui_custom_nodes: {} - comfyui_python_packages: {} comfyui_user_config: {} \ No newline at end of file