Document Docker image cleanup and add docker-prune script.

Explain safe prune vs aggressive prune, compose down --rmi local, and when to run after rebuilds.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-06-10 23:26:57 +08:00
parent 6265e56a7f
commit f22e3f4d16
4 changed files with 157 additions and 5 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
# 清理 Docker 无用镜像与构建缓存
# 用法:
# bash scripts/docker-prune.sh # 安全:悬空镜像 + 构建缓存
# bash scripts/docker-prune.sh --all # 额外删除未被任何容器使用的镜像
set -euo pipefail
APP_DIR="${APP_DIR:-/opt/zhimingge}"
cd "$APP_DIR" 2>/dev/null || cd "$(dirname "$0")/.."
echo "==> 当前磁盘占用"
docker system df
echo ""
echo "==> 当前知命阁相关镜像"
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Size}}\t{{.CreatedSince}}" \
| head -1
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.ID}}\t{{.Size}}\t{{.CreatedSince}}" \
| grep -E "zhimingge|^REPOSITORY" || true
echo ""
echo "==> 删除悬空镜像(<none>,多为 rebuild 后遗留)..."
docker image prune -f
echo "==> 清理构建缓存..."
docker builder prune -f
if [[ "${1:-}" == "--all" ]]; then
echo ""
echo "==> 删除未被任何容器使用的镜像(不含正在运行的 zhimingge:latest..."
docker image prune -a -f
fi
echo ""
echo "==> 清理后磁盘占用"
docker system df
echo ""
echo "完成。若仍占用较大,可查看:docker images -a"