Last active
June 21, 2016 13:56
-
-
Save marcelotmelo/3681fc53e4bc0250a75f78b13370e87c to your computer and use it in GitHub Desktop.
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
#list all volumes | |
docker volume ls | awk '{if(NR>1) print $2}' | sort > all_volumes | |
#list currently used volumes | |
docker ps -a | awk '{if(NR>1)print $1}' | xargs docker inspect | tr -d '\n' | grep -Po '"Mounts":.*?[^\\]",' | awk '/Name/ {print $5}' | tr -d '"' | tr -d ',' > used_volumes | |
#remove unused volumes | |
diff used_volumes all_volumes --suppress-common-lines | grep '>' | awk '{print $2}' | xargs docker volume rm | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Snippets for listing docker volumes
You should not do this unless you're sure about what you're doing. You will lose the data of you containers.