Files
dekun f22e3f4d16 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>
2026-06-10 23:26:57 +08:00

40 lines
1.1 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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"