From 1e3aa337dbe03e618a170c724d44ce02ecc3eb3a Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 11 May 2026 12:24:41 +0800 Subject: [PATCH] fix(cloud-image): refine cleanup process to prevent unwanted image deletions Updated the cleanup script to replace the broad `docker system prune` command with more targeted commands. This change ensures that only unused containers, build cache, and dangling volumes are removed, preventing the accidental deletion of important images like `wechatopenai/weknora-*` that are pre-pulled for firstboot. The script now explicitly prunes containers, builders, and dangling volumes to maintain a clean environment without disrupting the intended image setup. --- scripts/cloud-image/cleanup.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/scripts/cloud-image/cleanup.sh b/scripts/cloud-image/cleanup.sh index ad1f1a188..d899449d4 100755 --- a/scripts/cloud-image/cleanup.sh +++ b/scripts/cloud-image/cleanup.sh @@ -41,7 +41,14 @@ if [[ -n "${COMPOSE_PROJECT}" ]]; then docker volume ls -q --filter "label=com.docker.compose.project=${COMPOSE_PROJECT}" \ | xargs -r docker volume rm -f || true fi -docker system prune -af --volumes || true +# 注意: 这里只清"卷 / 已停容器 / 构建缓存", 绝对不能清镜像。 +# 此前用过 `docker system prune -af --volumes`, 会把 prepare.sh 预拉的 +# wechatopenai/weknora-* 等镜像一并清掉, 导致基于镜像建出来的新实例 +# 在 firstboot 时还要重新从 Docker Hub 拉数 GB 镜像, 完全违背预装初衷。 +docker container prune -f || true +docker builder prune -af || true +# 只清未挂载的 dangling 卷 (此时 compose down -v 已清掉业务卷) +docker volume prune -f || true echo "[cleanup] 4/8 清空系统日志" journalctl --rotate || true