Docker 部署 ComfyUI 快速升级方案

本文是对《基于 Docker 部署 ComfyUI》部署方案怎样快速升级 ComfyUI 的一个补充。

升级的方案有两种:

  • 在线更新:更新速度更快,只需要重启 ComfyUI 即可。
  • 离线更新:更新速度慢,但更加彻底,更新切换时间较长。

在线更新

首先需要知道的是 models output custom_nodes user 这 4 个目录不能被覆盖,所以在更新的时候,需要忽略这 4 个目录,官方已经考虑了这点,在更新时候忽略了这 4 个目录。为确保万一,可以使用以下方法检测是否忽略。

# 进入容器
[root@gpu-server-001 comfyui]# docker exec -u root -it comfyui bash

# 进入 ComfyUI 仓库目录
[root@gpu-server-001 app]$ cd ComfyUI

# 检测当前 Tag 报错如下,是因为变更了目录权限
[root@gpu-server-001 ComfyUI]$ git describe --tags --exact-match
fatal: detected dubious ownership in repository at '/app/ComfyUI'
To add an exception for this directory, call:

        git config --global --add safe.directory /app/ComfyUI

# 根据提示设置
[root@gpu-server-001 ComfyUI]$ git config --global --add safe.directory /app/ComfyUI

# 检测当前 Tag
[root@gpu-server-001 ComfyUI]$ git describe --tags --exact-match
v0.3.59

# 检测忽略文件或目录,可以看到 models/ output/ custom_nodes/ user/ 4 个目录是被忽略的
[root@gpu-server-001 ComfyUI]$ cat .gitignore
__pycache__/
*.py[cod]
/output/
/input/
!/input/example.png
/models/
/temp/
/custom_nodes/
!custom_nodes/example_node.py.example
extra_model_paths.yaml
/.vs
.vscode/
.idea/
venv/
.venv/
/web/extensions/*
!/web/extensions/logging.js.example
!/web/extensions/core/
/tests-ui/data/object_info.json
/user/
*.log
web_custom_versions/
.DS_Store
openapi.yaml
filtered-openapi.yaml
uv.lock

# 检查是否有被跟踪的文件,可以看到列出的文件不影响更新
[root@gpu-server-001 ComfyUI]$ git ls-files models/ output/ custom_nodes/ user/
custom_nodes/example_node.py.example
custom_nodes/websocket_image_save.py
models/audio_encoders/put_audio_encoder_models_here
models/checkpoints/put_checkpoints_here
models/clip/put_clip_or_text_encoder_models_here
models/clip_vision/put_clip_vision_models_here
models/configs/anything_v3.yaml
models/configs/v1-inference.yaml
models/configs/v1-inference_clip_skip_2.yaml
models/configs/v1-inference_clip_skip_2_fp16.yaml
models/configs/v1-inference_fp16.yaml
models/configs/v1-inpainting-inference.yaml
models/configs/v2-inference-v.yaml
models/configs/v2-inference-v_fp32.yaml
models/configs/v2-inference.yaml
models/configs/v2-inference_fp32.yaml
models/configs/v2-inpainting-inference.yaml
models/controlnet/put_controlnets_and_t2i_here
models/diffusers/put_diffusers_models_here
models/diffusion_models/put_diffusion_model_files_here
models/embeddings/put_embeddings_or_textual_inversion_concepts_here
models/gligen/put_gligen_models_here
models/hypernetworks/put_hypernetworks_here
models/loras/put_loras_here
models/model_patches/put_model_patches_here
models/photomaker/put_photomaker_models_here
models/style_models/put_t2i_style_model_here
models/text_encoders/put_text_encoder_files_here
models/unet/put_unet_files_here
models/upscale_models/put_esrgan_and_other_upscale_models_here
models/vae/put_vae_here
models/vae_approx/put_taesd_encoder_pth_and_taesd_decoder_pth_here
output/_output_images_will_be_put_here

开始更新 ComfyUI

# 进入仓库目录
[root@gpu-server-001 app]$ cd ComfyUI

# 拉取目标 tag(使用浅克隆,只拉该版本的提交)
[root@gpu-server-001 ComfyUI]$ git fetch --depth=1 origin tag v0.3.60
remote: Enumerating objects: 215, done.
remote: Counting objects: 100% (215/215), done.
remote: Compressing objects: 100% (92/92), done.
remote: Total 113 (delta 77), reused 40 (delta 16), pack-reused 0 (from 0)
Receiving objects: 100% (113/113), 66.98 KiB | 434.00 KiB/s, done.
Resolving deltas: 100% (77/77), completed with 72 local objects.
From https://github.com/comfyanonymous/ComfyUI
 * [new tag]         v0.3.60    -> v0.3.60

# 预览新旧 tag 在这四个目录下有哪些已跟踪文件会变动(没有输出,说明没有变动)
[root@gpu-server-001 ComfyUI]$ git diff --name-status v0.3.59 v0.3.60 -- models/ output/ custom_nodes/ user/

# 确认工作区干净(出现以下信息,是因为变更了目录权限)
[root@gpu-server-001 ComfyUI]$ git status
Not currently on any branch.
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   .ci/windows_base_files/run_nvidia_gpu_fast_fp16_accumulation.bat
        modified:   .ci/windows_nightly_base_files/run_nvidia_gpu_fast.bat
        modified:   .gitattributes
        modified:   .github/ISSUE_TEMPLATE/bug-report.yml
        modified:   .github/ISSUE_TEMPLATE/config.yml
        modified:   .github/ISSUE_TEMPLATE/feature-request.yml
        ......(略)

# 切换 Tag 报错如下,同样是因为变更了目录权限
[root@gpu-server-001 ComfyUI]$ git checkout v0.3.60
error: Your local changes to the following files would be overwritten by checkout:
        README.md
        comfy/audio_encoders/audio_encoders.py
        comfy/audio_encoders/wav2vec2.py
        comfy/k_diffusion/sampling.py
        ......(略)

# 强制切换
[root@gpu-server-001 ComfyUI]$ git checkout -f v0.3.60
Previous HEAD position was 72212fe ComfyUI version 0.3.59
HEAD is now at b873051 ComfyUI version 0.3.60

# 查看当前分支
[root@gpu-server-001 ComfyUI]$ git describe --tags --exact-match
v0.3.60

# 安装必要更新包
[root@gpu-server-001 app]# source venv/bin/activate
(venv) [root@gpu-server-001 app]# cd ComfyUI
(venv) [root@gpu-server-001 app]# pip install -r requirements.txt 
# 更新 comfyui frontend
(venv) [root@gpu-server-001 app]# pip install --no-cache-dir --upgrade comfyui-frontend-package
(venv) [root@gpu-server-001 app]# exit
exit

# 修改权限(非必要,根据实际情况)
[root@gpu-server-001 comfyui]# chown -R user:group ComfyUI
[root@gpu-server-001 comfyui]# chmod -R 2777 ComfyUI

# 重启 ComfyUI,生效更新
[root@gpu-server-001 comfyui]# docker restart comfyui

离线更新

离线更新,最重要的一点是 models output custom_nodes user 4 个目录的回迁问题。详细步骤如下:

  • 停止 ComfyUI 服务
  • 修改 docker-compose.yml 更新 Tag 版本信息
  • 取消 mount output 目录(非必要,如果 output 采用的共享目录必须)
  • 备份 ComfyUI 仓库目录
  • 启动 ComfyUI 服务
  • 回迁数据
  • 重新 mount output 目录(非必要,如果 output 采用的共享目录必须)
  • 再重启 ComfyUI 服务
# 停止 ComfyUI 服务
[root@gpu-server-001 ~]# cd /root/comfyui
[root@gpu-server-001 comfyui]# docker compose down

# 修改 docker-compose.yml,更新 Tag 版本信息
[root@gpu-server-001 comfyui]# cat docker-compose.yaml | grep Version
      ComfyUI_Version: v0.3.59
      ComfyUI_Manager_Version: 3.35

# 备份 ComfyUI 仓库目录
[root@gpu-server-001 comfyui]# mv ComfyUI ComfyUI-20250922

# 启动 ComfyUI 服务
[root@gpu-server-001 comfyui]# docker compose up -d

# 确保启动成功以后,再停止 ComfyUI 服务(出现以下日志说明启动成功)
[root@gpu-server-001 comfyui]# docker logs -f comfyui
Context impl SQLiteImpl.
Will assume non-transactional DDL.
No target revision found.
Starting server

To see the GUI go to: http://0.0.0.0:8188

# 停止 ComfyUI 服务
[root@gpu-server-001 comfyui]# docker compose down

# 修改权限(非必要,根据实际情况)
[root@gpu-server-001 comfyui]# chown -R user:group ComfyUI
[root@gpu-server-001 comfyui]# chmod -R 2777 ComfyUI

# 回迁数据(先删除新克隆仓库的以下 4 个目录,将旧 Tag 中的数据迁移回来)
[root@gpu-server-001 comfyui]# rm -rf ComfyUI/user/default/
[root@gpu-server-001 comfyui]# rm -rf ComfyUI/custom_nodes/
[root@gpu-server-001 comfyui]# rm -rf ComfyUI/models/
[root@gpu-server-001 comfyui]# rm -rf ComfyUI/output/
[root@gpu-server-001 comfyui]# mv ComfyUI-20250922/user/default ComfyUI/user/
[root@gpu-server-001 comfyui]# mv ComfyUI-20250922/custom_nodes ComfyUI/
[root@gpu-server-001 comfyui]# mv ComfyUI-20250922/models ComfyUI/
[root@gpu-server-001 comfyui]# mv ComfyUI-20250922/output ComfyUI/

# 安装必要更新包
[root@gpu-server-001 app]# source venv/bin/activate
(venv) [root@gpu-server-001 app]# cd ComfyUI
(venv) [root@gpu-server-001 app]# pip install -r requirements.txt 
# 更新 comfyui frontend
(venv) [root@gpu-server-001 app]# pip install --no-cache-dir --upgrade comfyui-frontend-package
# 检测包是否安装成功
(venv) [root@gpu-server-001 app]# pip list | grep frontend
comfyui_frontend_package          1.28.0
(venv) [root@gpu-server-001 app]# exit
exit
Avatar photo

关于 木子

Email: [email protected] 微信:rockylinuxcn QQ: 2306867585
Founder of the Rocky Linux Chinese community, MVP、VMware vExpert、TVP, advocate for cloud native technologies, with over ten years of experience in site reliability engineering (SRE) and the DevOps field. Passionate about Cloud Computing、Microservices、CI&CD、DevOps、Kubernetes, currently dedicated to promoting and implementing Rocky Linux in Chinese-speaking regions.
用一杯咖啡支持我们,我们的每一篇[文档]都经过实际操作和精心打磨,而不是简单地从网上复制粘贴。期间投入了大量心血,只为能够真正帮助到您。
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇