-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile_ComfyUI
79 lines (69 loc) · 4.15 KB
/
Dockerfile_ComfyUI
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
FROM python:3.10.6
ARG PROXY
ARG PORT=7960
# 设置pip源为阿里云pip源
ENV PIP_INDEX_URL=https://mirrors.aliyun.com/pypi/simple/
# debian 下安装访问 http://deb.debian.org/debian 等需要设置代理
# ENV http_proxy="http://${PROXY}"
# ENV https_proxy="http://${PROXY}"
# ENV all_proxy="socks5://${PROXY}"
# 安装基础包
RUN --mount=type=cache,target=/var/cache/apt \
export http_proxy="http://${PROXY}" https_proxy="http://${PROXY}" all_proxy="socks5://${PROXY}" && \
env | grep proxy && echo "----- install vim net-tools telnet libgl1 -----" && \
apt-get update && \
apt-get install -y vim-tiny net-tools telnet && \
# resolv ImportError: libGL.so.1: cannot open shared object file: No such file or directory
# when Launching Web UI with arguments
# see https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/10411
apt-get install -y libgl1
# 安装 ComfyUI 依赖的 torch, torchvision, 方便 docker build 缓存;
# torch版本号来自 stable-diffusion-webui/modules/launch_utils.py
# grep "torch_command = os.environ.get('TORCH_COMMAND'" modules/launch_utils.py | cut -d '"' -f 2 | cut -d '{' -f 1 | xargs -I {} python3 -m {} https://download.pytorch.org/whl/cu118
RUN --mount=type=cache,target=/root/.cache/pip ls -l /root/.cache/pip && \
# 安装 torch 不能设置代理,否则2g+的包下载不下来
export http_proxy="" https_proxy="" all_proxy="" && \
env | grep proxy && echo "----- install torch and torchvision -----" && \
# resolv the err: Using SOCKS proxy, but the 'socksio' package is not installed
# pip install httpx[socks] && \
pip install torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/cu121
#############################################################################################
#
# 要求在 host 上已经 clone 好的 ComfyUI 的同级目录下执行,即 Dockerfile 和 ComfyUI 平级,例如
# drwxr-xr-x 17 root root 4096 Dec 8 18:23 ComfyUI/
# -rw-r--r-- 1 root root 8550 Dec 7 23:26 Dockerfile_ComfyUI
#
COPY ./ComfyUI /home/comfyui
WORKDIR /home/comfyui
# 安装 requirements.txt
RUN --mount=type=cache,target=/root/.cache/pip ls -l /root/.cache/pip && \
echo "----- install requirements -----" && \
pip install -r requirements.txt
# 提前安装 ComfyUI-Manager、comfyui_controlnet_aux、mixlab-nodes、ComfyUI_Custom_Nodes_AlekPet 等插件需要的依赖到镜像中.
# 需要提前将 https://github.com/shadowcz007/comfyui-mixlab-nodes 等插件仓库 clone 到 ComfyUI/custom_nodes 目录下
RUN --mount=type=cache,target=/root/.cache/pip ls -l /root/.cache/pip && \
echo "----- install requirements of ComfyUI-Manager -----" && \
pip install -r custom_nodes/ComfyUI-Manager/requirements.txt && \
echo "----- install requirements of comfyui_controlnet_aux -----" && \
pip install -r custom_nodes/comfyui_controlnet_aux/requirements.txt && \
echo "----- install requirements of mixlab-nodes -----" && \
# 直接安装其内容:https://github.com/shadowcz007/comfyui-mixlab-nodes/blob/main/requirements.txt
# pip install numpy pyOpenSSL watchdog opencv-python-headless matplotlib
pip install -r custom_nodes/comfyui-mixlab-nodes/requirements.txt && \
echo "----- install requirements of ComfyUI_Custom_Nodes_AlekPet -----" && \
pip install -r custom_nodes/ComfyUI_Custom_Nodes_AlekPet/ArgosTranslateNode/requirements.txt && \
pip install -r custom_nodes/ComfyUI_Custom_Nodes_AlekPet/TranslateNode/requirements.txt && \
pip install -r custom_nodes/ComfyUI_Custom_Nodes_AlekPet/ArgosTranslateNode/requirements.txt && \
ls -l custom_nodes
EXPOSE ${PORT}
ENV PORT=${PORT}
CMD python -u main.py --listen --port ${PORT}
#
# ----- 用法 -----
# 构建镜像:
# nohup docker build -f ./Dockerfile_ComfyUI --build-arg PROXY=10.10.0.8:10887 --build-arg PORT=7980 -t sd-comfyui:20231214 . > build.log 2>&1 &
# tail -100f build.log
#
# 用构建好的镜像,启动后台运行容器:
# docker run --name sd-comfyui --gpus all -d -p 7980:7980 -v "${PWD}/ComfyUI/custom_nodes:/home/comfyui/custom_nodes" -v "${PWD}/models:/home/comfyui/models" -v "${PWD}/outputs:/home/comfyui/output" sd-comfyui:20231214
#