ComfyUI/Dockerfile
2025-11-30 18:07:44 -05:00

78 lines
2.8 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Docker buildfile for the ComfyUI image, with support for hardware
# acceleration, file ownership synchronization, custom nodes, and custom node
# managers.
# Use the recommended Python version 3.12, as specified in the README.
FROM python:3.12.11-bookworm AS comfyui-base
ARG APT_EXTRA_PACKAGES
# Install cmake, which is an indirect installation dependencies
RUN apt-get update && apt-get install -y --no-install-recommends cmake
# Create a mount point for user-generated data.
RUN mkdir -p \
/data/input \
/data/output \
/data/temp \
/data/user
# Create a regular user whose UID and GID will match the host user's at runtime.
# Also create a home directory for this user (-m), as some common Python tools
# (such as uv) interact with the users home directory.
RUN useradd -m comfyui
USER comfyui
# Install ComfyUI under /comfyui.
WORKDIR /comfyui
# Set up a Python virtual environment and configure it as the default Python.
#
# Reasons for using a virtual environment:
# - Some custom nodes use third-party tools like uv, which do not support
# user-level installations.
# - Custom node managers may install or update dependencies as the regular user,
# so a global installation is not an option.
# This leaves virtual environments as the only viable choice.
RUN python -m venv .venv
ENV PATH="/comfyui/.venv/bin:$PATH"
# Install Python dependencies. This step is also performed automatically by the
# entrypoint script, but doing it at build time reduces startup time on the
# first run.
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
# Install ComfyUI and link the data mount points.
COPY . .
RUN ln -sf /data/* .
# Purely declarative: inform Docker and image users that this image is designed
# to listen on port 8188 for the web GUI.
EXPOSE 8188
# Declare persistent volumes:
# - /data: stores user-generated data from ComfyUI,
# - /comfyui/.venv: stores Python data generated by the entrypoint and custom
# node managers,
# - /comfyui/custom_nodes: stores custom nodes installed at runtime by custom
# node managers,
# - /comfyui/models: Stores models installed by model managers,
# - /home/comfyui: stores data from Python packages that may write outside the
# virtual environment and into the users home directory.
VOLUME [ "/data", "/comfyui/.venv", "/comfyui/custom_nodes", "/comfyui/models", "/home/comfyui" ]
# Switch back to root to run the entrypoint and to install additional system
# dependencies
USER root
# Install additional system dependencies
RUN apt-get install -y --no-install-recommends $APT_EXTRA_PACKAGES \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
# Configure entrypoint
RUN chmod +x entrypoint.sh
ENTRYPOINT [ "./entrypoint.sh" ]
CMD [ "python", "./main.py" ]