1 摘要
使用一台安装了RTX4060显卡8G显存的笔记本用ComfyUI绘图。笔记本安装了Ubuntu26.04操作系统,使用Docker部署服务,已经安装好了显卡驱动和cuda-13对Dockers的支持包,远程操作ComfyUI绘图。文中用到的一些软件或者模型需要**才能下载到。
2 部署ComfyUI
由于ComfyUI官方不提供Docker镜像,只能使用第三方的,尽量找更新比较频繁,下载量比较大的版本,例如:
- runpod/comfyui,这个在dockerhub上可以搜到,国内使用 docker.1ms.run/runpod/comfyui 镜像可以下载。
- pixeloven/ComfyUI-Docker,在 https://github.com/pixeloven/ComfyUI-Docker 页面可以看到下载链接。
- YanWenKun/ComfyUI-Docker,在dockerhub上可以搜到,国内使用 docker.1ms.run/comfyui-boot 镜像可以下载
本例中使用YanWenKun/ComfyUI-Docker,下载cu130-slim镜像,重命名方便后续操作。
bash
root@sv100:/data# docker pull docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824
cu130-slim-20260824: Pulling from yanwk/comfyui-boot
759d2dcdcaa6: Pulling fs layer
4f4fb700ef54: Pulling fs layer
de0747fe6dba: Pulling fs layer
675358b533c7: Pulling fs layer
a93375d36493: Pulling fs layer
da60e9ef36a3: Pulling fs layer
d54b442e49a3: Pulling fs layer
1aafdcf98649: Pulling fs layer
1e91ce885830: Pulling fs layer
5b44b82bc34d: Pulling fs layer
27f9f1b929d8: Pulling fs layer
212ede86541b: Pulling fs layer
791589200043: Pulling fs layer
3b53b200b79f: Pulling fs layer
b62878f4866a: Pulling fs layer
b925314ef2cc: Pulling fs layer
f59c682e5ef4: Pulling fs layer
5f3133043926: Pulling fs layer
fa0f94c8c640: Pulling fs layer
bef5f522dce3: Pulling fs layer
853131fd3ff3: Pulling fs layer
f18bddae2a77: Pulling fs layer
f43c79143108: Pulling fs layer
093168f800b8: Pulling fs layer
3be18e82b5ea: Pulling fs layer
45761109436e: Pulling fs layer
Digest: sha256:4eaa8d1be7adb1c49cc2cbd536e0c28e062eac00c9c7b902c591473d0c0fe090
Status: Downloaded newer image for docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824
docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824
root@sv100:/data# docker tag docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824 comfyui:20260824
root@sv100:/data# docker image rm docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824
Untagged: docker.1ms.run/yanwk/comfyui-boot:cu130-slim-20260824
YanWenKun/ComfyUI-Docker 在 https://github.com/YanWenKun/ComfyUI-Docker/blob/main/README.zh.adoc 有中文版本的说明,按照说明配置docker编排文件,创建数据目录。
yaml
services:
comfyui:
image: comfyui:20260824
container_name: comfyui
restart: always
environment:
- CLI_ARGS=--lowvram
- COMFY_PORT=8188
ports:
- "8188:8188"
volumes:
- /data/Comfyui/data/dot-cache:/root/.cache
- /data/Comfyui/data/dot-config:/root/.config
- /data/Comfyui/data/dot-local:/root/.local
- /data/Comfyui/data/custom_nodes:/root/ComfyUI/custom_nodes
- /data/Comfyui/data/models:/root/ComfyUI/models
- /data/Comfyui/data/hf-hub:/root/.cache/huggingface/hub
- /data/Comfyui/data/torch-hub:/root/.cache/torch/hub
- /data/Comfyui/data/input:/root/ComfyUI/input
- /data/Comfyui/data/output:/root/ComfyUI/output
- /data/Comfyui/data/user-profile:/root/ComfyUI/user
- /data/Comfyui/data/user-scripts:/root/user-scripts
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: all
capabilities: [gpu]
之后可以启动docker了,查看日志,确定镜像成功启动。
bash
root@sv100:/data/Comfyui# docker compose up -d
[+] up 2/2
✔ Network comfyui_default Created 0.1s
✔ Container comfyui Started 0.3s
root@sv100:/data/Comfyui# docker compose logs -f
comfyui | ########################################
comfyui | [INFO] Setting up ComfyUI...
comfyui | [INFO] Using image-bundled ComfyUI (copied to workdir).
comfyui | [INFO] Starting ComfyUI...
comfyui | ########################################
............
此处省略
............
comfyui | [INFO] To see the GUI go to: http://0.0.0.0:8188
comfyui | [INFO] To see the GUI go to: http://[::]:8188
此时,打开浏览器链接网站的8188端口,可以看到
3 下载模型
使用ComfyUI绘图一般需要两个模型,一个是绘图模型,一个是扩图模型。
先下载绘图模型,访问 https://civitai.com/ 网站,注册账号并登录。在网站中点击左上方的models菜单,然后点击右上方的filter按钮,筛选模型。其中模型类型选择Checkpoint,就可以进行筛选,一般选择时间比较近的,模型大小在8G以内的。比如CyberRealistic这个模型。
点击右方的下载链接,会下载到一个.safetensors文件,比如本例就是cyberrealistic_final.safetensors,将其拷贝到Docker容器的数据目录下的models/checkpoints目录下。
一般RTX4060可以跑的绘图模型绘出来的图都不大,比如512×768,让其绘制更大的图,就很可能出现混乱。所以就只让其画小图,然后再使用扩图模型扩图。这里我们使用4x-UltraSharpV2,可以在HuggingFace搜索下载,比如 https://huggingface.co/GeraldoZulimar/4x-UltraSharpV2/ ,会下载到一个.pth文件,将其放在Docker容器的数据目录下的models/upscale_models目录下。
bash
root@sv100:/data/Comfyui# ls -l data/models/checkpoints/cyberrealistic_final.safetensors
-rw-rw-r-- 1 root root 2132651162 Aug 25 12:40 data/models/checkpoints/cyberrealistic_final.safetensors
root@sv100:/data/Comfyui# ls -l data/models/upscale_models/4x-UltraSharpV2.pth
-rw-rw-r-- 1 root root 140335046 Aug 25 12:40 data/models/upscale_models/4x-UltraSharpV2.pth
4 建立流程
首先在网站工作区添加节点,在工作区空白处双击,可以呼唤出节点选择器,然后在其中搜索就可以添加节点了。
在工作区添加以下节点:
-
Checkpoint加载器
-
K采样器
-
Clip文本编码(需要两个)
-
空Latent图像
-
VAE解码
-
加载放大模型
-
使用模型放大图像
-
保存图像
然后开始在节点间连线: -
Checkpoint加载器的模型连接到K采样器的模型。
-
Checkpoint加载器的Clip分别连接到两个Clip文本编码的Clip。
-
Checkpoint加载器的VAE连接到VAE解码的VAE。
-
两个Clip文本编码的条件分别连接到K采样器的正面条件和负面条件。
-
空Latent图像的Latent连接到K采样器的Latent图像。
-
K采样器的Latent连接到VAE解码的Latent。
-
VAE解码的图像连接到使用模型放大图像的图像。
-
加载放大模型的放大模型连接到使用模型放大图像的放大模型。
-
使用模型放大图像的图像连接到保存图像的图片。
然后,在Checkpoint中选择刚才下载的cyberrealistic_final.safetensors画图模型,在加载放大模型中选择刚下载的4x-UltraSharpV2.pth模型。在空Latent中设置绘图的大小,如512×768,在K采样器中调节参数,如步数设置为30,cfg设置为7.5,采样器设置为dpmpp_2m等。
之后,就是在Clip文本编码中写正面描绘和负面描绘的提示词了,这些提示词一般用中文写会效果不佳,可以用其他大模型去写提示词。将提示词复制到正面和负面的Clip文本编码中,然后点击右上角的运行开始绘制图片。
绘制好后,在左侧的媒体资产中可以看到图片,也可以再保存图像那里右键打开图像,查看大图。
最后看一下绘制好的大图。