分享一个在CNB云原生构建ComfyUI运行环境的项目。
cnb-xu/comfyui · Cloud Native Build
Dockerfile:
FROM nvidia/cuda:12.8.0-cudnn-devel-ubuntu24.04
# 设置 CUDA 路径
ENV CUDA_HOME=/usr/local/cuda
# 安装依赖并清理缓存
RUN apt update -y
&& apt install -y --no-install-recommends
libaio-dev libfmt-dev libgflags-dev libssl-dev libcurl4-openssl-dev libtbb-dev zlib1g-dev
libglx-mesa0 mesa-utils libgthread-2.0-0
cmake g++ gcc git git-lfs jq openssh-server patchelf tree vim
aria2 curl ffmpeg wget
python3 python3-dev python3-pip python3-venv
&& rm -rf /var/lib/apt/lists/*
# 安装 code-server 和扩展
RUN curl -fsSL https://code-server.dev/install.sh | sh
&& code-server --install-extension ms-python.python
&& code-server --install-extension ms-python.flake8
&& code-server --install-extension ms-python.black-formatter
&& code-server --install-extension ms-python.mypy-type-checker
&& code-server --install-extension ms-python.pylint
&& code-server --install-extension ms-python.debugpy
&& code-server --install-extension ms-ceintl.vscode-language-pack-zh-hans
&& code-server --install-extension cnbcool.cnb-welcome
&& code-server --install-extension tencent-cloud.coding-copilot
# 生成vscode中文插件必要的配置文件
# 此处脚本来源于https://cnb.cool/examples/ecosystem/chinese-env
# 采用下载方式引入脚本文件
RUN curl -o /tmp/create_languagepacks "https://cnb.cool/examples/ecosystem/chinese-env/-/git/raw/main/.ide/create_languagepacks?download=true"
RUN chmod +x /tmp/create_languagepacks && /tmp/create_languagepacks && rm -f /tmp/create_languagepacks
ENV LANG C.UTF-8
ENV LANGUAGE C.UTF-8
生成venv并启动ComfyUI:
# 创建venv
python3 -m venv venv
# 激活venv
source venv/bin/activate
# 更新pip
pip install --upgrade pip
# 安装build wheel
pip install build wheel
# 安装torch-2.7.1+cu128
pip install torch==2.7.1 torchvision==0.22.1 torchaudio==2.7.1 --index-url https://download.pytorch.org/whl/cu128
# 安装xformers
pip install xformers --index-url https://download.pytorch.org/whl/cu128
# 克隆ComfyUI仓库
git clone https://github.com/comfyanonymous/ComfyUI.git
# 安装ComfyUI依赖
pip install -r ComfyUI/requirements.txt
# 克隆ComfyUI-Manager仓库
git clone https://github.com/ltdrdata/ComfyUI-Manager.git ComfyUI/custom_nodes/ComfyUI-Manager
# 安装ComfyUI-Manager依赖
pip install -r ComfyUI/custom_nodes/ComfyUI-Manager/requirements.txt
# 启动ComfyUI
venv/bin/python ComfyUI/main.py --listen --auto-launch
