Last active
March 10, 2017 12:25
-
-
Save mindw/4d2fc53ee69fe20e41bfb570a0ac3a06 to your computer and use it in GitHub Desktop.
Docker shortcuts
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
| # clenup all exited containers | |
| docker rm -v $(docker ps -a -q -f status=exited) | |
| $(docker ps -a -q -f status=exited) | xargs -r docker rm -v | |
| # remove dangling images | |
| docker rmi $(docker images -f "dangling=true" -q) | |
| $(docker images -f "dangling=true" -q) | xargs -r docker rmi -v | |
| # remove dangling volumes | |
| docker volume rm $(docker volume ls -qf dangling=true) | |
| # Delete all tagged images more than a month old | |
| # (will fail to remove images still used). | |
| docker images --no-trunc --format '{{.ID}} {{.CreatedSince}}' | grep -E ' (months|weeks)' | \ | |
| awk '{ print $1 }' | xargs --no-run-if-empty docker rmi {} || true | |
| # same but using names which will untag and allow remove duplicates | |
| docker images --no-trunc --format '{{.Repository}}:{{ .Tag }} {{.CreatedSince}}' | \ | |
| grep -E ' (months|weeks)' | awk '{ print $1 }' | gxargs --no-run-if-empty docker rmi {} || true | |
| # Delete all 'untagged/dangling' (<none>) images | |
| # Those are used for Docker caching mechanism. | |
| docker images -q --no-trunc --filter dangling=true | xargs --no-run-if-empty docker rmi | |
| # Delete all dangling volumes. | |
| docker volume ls -qf dangling=true | xargs --no-run-if-empty docker volume rm |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment