Skip to content

Instantly share code, notes, and snippets.

@afsalrahim
Created May 15, 2026 13:30
Show Gist options
  • Select an option

  • Save afsalrahim/7d6db8bbe79287a071a8d45dc45e3b01 to your computer and use it in GitHub Desktop.

Select an option

Save afsalrahim/7d6db8bbe79287a071a8d45dc45e3b01 to your computer and use it in GitHub Desktop.
Docker Verbose Audit & Cleanup: A Coolify-optimized script to identify bloated images and safely reclaim disk space.
#!/bin/bash
# --- COLORS ---
BLUE='\033[0;34m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'
echo -e "${BLUE}=============================================${NC}"
echo -e "${BLUE} DOCKER VERBOSE AUDIT ${NC}"
echo -e "${BLUE}=============================================${NC}\n"
# 1. DOCKER RESOURCE SUMMARY
echo -e "${YELLOW}[1] DOCKER RESOURCE SUMMARY${NC}"
docker system df
echo ""
# 2. TOP LARGEST IMAGES
echo -e "${YELLOW}[2] TOP LARGEST IMAGES${NC}"
docker images --format "{{.Size}}\t{{.ID}}\t{{.Repository}}:{{.Tag}}" | sort -hr | head -n 8 | while read -r line; do
IMG_ID=$(echo $line | awk '{print $2}')
APP_NAME=$(docker inspect "$IMG_ID" --format '{{index .Config.Labels "coolify.applicationId"}}' 2>/dev/null)
if [ -z "$APP_NAME" ] || [ "$APP_NAME" == "<no value>" ]; then APP_NAME=$(echo $line | awk '{print $3}'); fi
echo -e "${GREEN}$(echo $line | awk '{print $1}')${NC}\t$IMG_ID\t$APP_NAME"
done
echo ""
# 3. DANGLING VOLUME DETAILS
echo -e "${YELLOW}[3] UNUSED (DANGLING) VOLUMES${NC}"
DANGLING_VOLS=$(docker volume ls -qf dangling=true)
if [ -z "$DANGLING_VOLS" ]; then
echo -e "${GREEN}No orphaned volumes found.${NC}"
else
for vol in $DANGLING_VOLS; do
LABEL=$(docker volume inspect "$vol" --format '{{index .Labels "coolify.name"}}' 2>/dev/null)
if [ -z "$LABEL" ] || [ "$LABEL" == "<no value>" ]; then LABEL="${YELLOW}[Internal Layer]${NC}"; fi
printf "%-40s | %-30s\n" "$vol" "$LABEL"
done
fi
echo ""
# 4. ACTION MENU
echo -e "${BLUE}---------------------------------------------${NC}"
echo -e "${YELLOW}Which action would you like to take?${NC}"
echo "1) Clear Build Cache (Fixes 'Max Attempts' errors)"
echo "2) Remove Dangling Images (Safe - unnamed layers)"
echo "3) Remove ALL Unused Images (Cleans old app versions)"
echo "4) Remove Dangling Volumes (Removes the list in Step 3)"
echo "5) Exit"
echo -ne "${GREEN}Select an option [1-5]: ${NC}"
read choice
case $choice in
1) docker builder prune -f ;;
2) docker image prune -f ;;
3)
echo -e "${RED}Deleting all unused images...${NC}"
docker image prune -a -f ;;
4) docker volume prune -f ;;
5) exit 0 ;;
esac
echo -e "\n${BLUE}Maintenance Task Complete.${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment