Skip to content

Instantly share code, notes, and snippets.

@ragnarok22
Created February 2, 2026 13:35
Show Gist options
  • Select an option

  • Save ragnarok22/cd0b1317fea78140117af9adcb09d388 to your computer and use it in GitHub Desktop.

Select an option

Save ragnarok22/cd0b1317fea78140117af9adcb09d388 to your computer and use it in GitHub Desktop.
Clean up unused Docker resources (containers, networks, volumes, images, and build cache)
#!/usr/bin/env bash
# clean-docker.sh
# Description: Clean up unused Docker resources (containers, networks, volumes, images, and build cache)
#
# Usage:
# chmod +x clean-docker.sh
# ./clean-docker.sh
#
# Or run directly with:
# curl -sL <raw-url> | bash
set -euo pipefail
echo "==> Removing stopped containers..."
docker container prune -f
echo "==> Removing unused networks..."
docker network prune -f
echo "==> Removing unused volumes..."
docker volume prune -f
echo "==> Removing dangling images..."
docker image prune -f
echo "==> Removing build cache..."
docker builder prune -f
echo "==> Disk usage after cleanup:"
docker system df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment