Skip to content

Instantly share code, notes, and snippets.

@kytta
Created November 30, 2019 12:44
Show Gist options
  • Save kytta/461ae43c2cef494f44e8d322606dc778 to your computer and use it in GitHub Desktop.
Save kytta/461ae43c2cef494f44e8d322606dc778 to your computer and use it in GitHub Desktop.
Docker Deep Clean — a script to remove all unused Docker containers, images and volumes
#!/bin/bash
echo "Removing exited containers..."
echo "============================="
docker ps --filter status=dead --filter status=exited -aq | xargs docker rm -v
echo ""
echo "Removing unused images..."
echo "========================="
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs docker rmi
echo ""
echo "Removing unused volumes..."
echo "=========================="
docker volume ls -qf dangling=true | xargs docker volume rm
echo ""
echo "Done."
@kytta
Copy link
Author

kytta commented Nov 30, 2019

Cred to @mlebkowski for his post

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment