Skip to content

Instantly share code, notes, and snippets.

@dominickm
Created October 31, 2025 08:37
Show Gist options
  • Select an option

  • Save dominickm/273661981464d3cf89d3a977480090a3 to your computer and use it in GitHub Desktop.

Select an option

Save dominickm/273661981464d3cf89d3a977480090a3 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -euo pipefail
echo "== Disk usage (filesystem) =="
df -h
echo
echo "== Docker disk usage summary =="
docker system df || true
echo
echo "== Top 15 images by size =="
docker images --format '{{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}' | head -n 1 && \
docker images --format '{{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}' | tail -n +2 | sort -hk3 -r | head -n 15
echo
echo "== Dangling images (safe to prune) =="
docker images -f "dangling=true" -q | sort -u
echo
echo "== Stopped containers (safe to remove) =="
docker ps -a -f "status=exited" -q | sort -u
# Dokku-specific insights (skip if dokku not present)
if command -v dokku >/dev/null 2>&1; then
echo
echo "== Dokku builder info =="
dokku builder:list || true
echo
echo "== Dokku app images (per app) =="
dokku apps:list | tail -n +2 | while read -r app; do
[ -z "$app" ] && continue
echo "-- $app --"
dokku ps:report "$app" | sed 's/^/ /'
dokku tags:list "$app" 2>/dev/null | sed 's/^/ /' || true
done
fi
echo
echo "== PRUNE (safe defaults) =="
read -p "Prune dangling images, stopped containers, build cache? [y/N] " go
if [[ "${go:-N}" =~ ^[Yy]$ ]]; then
docker container prune -f
docker image prune -f
docker builder prune -f
docker volume prune -f
fi
echo
echo "== OPTIONAL: stronger prune (unused images not just dangling) =="
echo "Run manually if needed:"
echo " docker image prune -a -f"
echo
echo "== OPTIONAL: clear layers from old Dokku releases (per app) =="
echo "# Example (replace <app>):"
echo " dokku ps:stop <app> && dokku ps:rebuild <app>"
echo " # Or remove stale images by tag:"
echo " docker images | grep <app> | awk '{print \$3}' | xargs -r docker rmi"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment