Created
September 17, 2020 20:38
-
-
Save Pictor13/2f126bf16708b380cd0289aed03a0115 to your computer and use it in GitHub Desktop.
Clean up docker (credits: 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 (needs to be ran as root): | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment