Created
November 6, 2016 02:59
-
-
Save khanhicetea/9e1972a12f0d9a1ef3e5531d3a7c5cb0 to your computer and use it in GitHub Desktop.
Docker Garbage Collector
This file contains hidden or 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
$ # Ref : https://github.com/docker/docker/pull/26108#issuecomment-243259942 | |
$ # caveat that you get warnings on things that can't be removed | |
$ # remove all stopped containers | |
$ docker ps -aq | xargs --no-run-if-empty docker rm | |
$ # remove all unused volumes | |
$ docker volume ls -q | xargs --no-run-if-empty docker volume rm | |
$ # remove local volumes | |
$ docker volume ls | awk '/^local/ { print $2 }' | xargs --no-run-if-empty docker volume rm | |
$ # delete untagged images | |
$ docker images --filter dangling=true -q | xargs --no-run-if-empty docker rmi | |
$ # delete and untag every image that is not a container | |
$ # a little more heinous since "<none>" is the repo/tag for dangling images | |
$ docker images | awk 'NR>1 { if ($1 == "<none>") print $3; else print $1":"$2 }' | sort | xargs --no-run-if-empty docker rmi | |
$ # sort is not necessary but is nice if you add a -tn1 to xargs so you can see each rm line |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment