Last active
September 10, 2016 11:37
-
-
Save maximd/1e0d0559fc873153588ad0504a53e238 to your computer and use it in GitHub Desktop.
docker-gc
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 | |
# | |
# docker-gc - remove stopped docker containers and images | |
# | |
# inspired by: | |
# - https://forums.docker.com/t/command-to-remove-all-unused-images/20/2 | |
# - http://stackoverflow.com/a/24681946/576371 | |
docker ps -qaf status=exited | xargs docker rm | |
docker images -qf dangling=true | xargs docker rmi | |
# it would be better to use "--no-run-if-empty" option for xargs as described in https://gist.github.com/ngpestelos/4fc2e31e19f86b9cf10b#gistcomment-1769502 | |
# but xargs does not support this option on Mac | |
# more information about dangling images at http://www.projectatomic.io/blog/2015/07/what-are-docker-none-none-images/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment