Last active
November 13, 2023 20:14
-
-
Save mlebkowski/471d2731176fb11e81aa to your computer and use it in GitHub Desktop.
Cleanup docker disk space https://lebkowski.name/docker-volumes/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# remove exited containers: | |
docker ps --filter status=dead --filter status=exited -aq | xargs -r docker rm -v | |
# remove unused images: | |
docker images --no-trunc | grep '<none>' | awk '{ print $3 }' | xargs -r docker rmi | |
# remove unused volumes: | |
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <( | |
docker ps -aq | xargs docker inspect | jq -r '.[] | .Mounts | .[] | .Name | select(.)' | |
) | xargs -r rm -fr |
As of today, all prune commands were merged into single docker system prune
: https://docs.docker.com/engine/reference/commandline/system_prune/#examples
Which is a terrible design choice because it unknowingly purges just about everything useful to use Docker by default, which causes a ton of development overhead helping colleagues recover network configuration, etc. when simply trying to free up space on the system.
Docker seems to mess up just about everything they do.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@zaplatynski 👏 🎉