mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2026-01-15 00:30:55 +08:00
85 lines
3.0 KiB
Docker
85 lines
3.0 KiB
Docker
# Docker buildfile for the ComfyUI image, with support for hardware
|
||
# acceleration, file ownership synchronization, custom nodes, and custom node
|
||
# managers.
|
||
#
|
||
# Authors:
|
||
# B. Bergeron <me@bbergeron.xyz>
|
||
#
|
||
|
||
# Use the recommended Python version 3.12, as specified in the README.
|
||
FROM python:3.12.11-bookworm AS comfyui-base
|
||
|
||
# Install cmake, which is an indirect installation dependencies
|
||
RUN apt update \
|
||
&& apt install -y --no-install-recommends cmake \
|
||
&& apt clean \
|
||
&& rm -rf /var/lib/apt/lists/*
|
||
|
||
# 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 user’s 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,
|
||
# - /home/comfyui: stores data from Python packages that may write outside the
|
||
# virtual environment and into the user’s home directory.
|
||
VOLUME [ "/data", "/comfyui/.venv", "/comfyui/custom_nodes", "/home/comfyui" ]
|
||
|
||
# Switch back to root to run the entrypoint and ensure it is executable.
|
||
USER root
|
||
RUN chmod +x entrypoint.sh
|
||
ENTRYPOINT [ "./entrypoint.sh" ]
|
||
CMD [ "python", "./main.py" ]
|
||
|
||
# Known issue: Some custom nodes require additional system dependencies, which
|
||
# are not as easy to install as Python dependencies. If this is the case, you
|
||
# can use the instruction below to install the required packages.
|
||
#RUN apt update \
|
||
# && apt install -y --no-install-recommends \
|
||
# package-1 \
|
||
# package-2 \
|
||
# ... \
|
||
# && apt clean \
|
||
# && rm -rf /var/lib/apt/lists/*
|