Created
October 13, 2016 09:57
-
-
Save mauricioprado00/bc3869f7c9397af3437cbd0b1b8f9be4 to your computer and use it in GitHub Desktop.
docker build cleanup
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
#!/usr/bin/env bash | |
# see https://lebkowski.name/docker-volumes/ | |
# The command doesn’t remove anything, but simply passing the results to xargs -r rm -fr does so. | |
find '/var/lib/docker/volumes/' -mindepth 1 -maxdepth 1 -type d | grep -vFf <( | |
docker ps -aq | xargs docker inspect | jq -r '.[]|.Mounts|.[]|.Name|select(.)' | |
) | |
# Hint: docker 1.9 has new volume management system, so it’s way easier with this version: | |
# docker volume ls -qf dangling=true | xargs -r docker volume rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment