fix(cleanup): preserve volumes in make clean, add make clean-all

This commit is contained in:
Yury Kossakovsky
2025-12-28 11:26:02 -07:00
parent 886234f91f
commit 975df4afb4
2 changed files with 18 additions and 20 deletions

View File

@@ -1,38 +1,29 @@
#!/bin/bash
# =============================================================================
# docker_cleanup.sh - Complete Docker system cleanup
# docker_cleanup.sh - Docker system cleanup (preserves volumes)
# =============================================================================
# Aggressively cleans up the Docker system to reclaim disk space.
# WARNING: This action is irreversible!
# Cleans up the Docker system to reclaim disk space.
#
# Removes:
# - All stopped containers
# - All networks not used by at least one container
# - All unused images (not just dangling ones)
# - All unused volumes
# - All build cache
#
# Preserves:
# - All volumes (to protect application data like Redis, PostgreSQL, etc.)
#
# Usage: make clean OR sudo bash scripts/docker_cleanup.sh
# =============================================================================
set -e
# Source the utilities file
source "$(dirname "$0")/utils.sh"
log_info "Starting Docker cleanup..."
# The 'docker system prune' command removes:
# - all stopped containers
# - all networks not used by at least one container
# - all "dangling" (unreferenced) images
# - all build cache
#
# Additional flags:
# -a, --all: Remove all unused images, not just dangling ones.
# --volumes: Remove all unused volumes.
# -f, --force: Do not prompt for confirmation.
# Clean containers, networks, images, and build cache
# NOTE: --volumes flag removed to preserve application data
docker system prune -a -f
docker system prune -a --volumes -f
log_success "Docker cleanup completed successfully."
log_success "Docker cleanup completed. Volumes preserved."