mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-19 10:53:29 +00:00
Merge pull request #1 from RedsAnalysis/dockerfile-branch
Dockerfile branch
This commit is contained in:
commit
b460dd62df
61
Dockerfile
Normal file
61
Dockerfile
Normal file
@ -0,0 +1,61 @@
|
||||
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
|
||||
|
||||
# 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
|
||||
|
||||
# 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'"]
|
91
docker-build.sh
Normal file
91
docker-build.sh
Normal file
@ -0,0 +1,91 @@
|
||||
#!/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
|
||||
|
||||
# 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)
|
||||
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
|
||||
|
||||
# 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
|
||||
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 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 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."
|
26
docker-compose.yml
Normal file
26
docker-compose.yml
Normal file
@ -0,0 +1,26 @@
|
||||
services:
|
||||
comfyui_backend:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Dockerfile
|
||||
image: comfyui-red-image
|
||||
container_name: comfyui-red-container
|
||||
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
|
||||
- ./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)
|
||||
|
||||
|
||||
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
|
Loading…
Reference in New Issue
Block a user