Last active
April 12, 2016 14:42
-
-
Save t3hk0d3/6c52b9972f20c3750e97 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
#!/bin/sh -e | |
# Delete all stopped containers (including data-only containers). | |
docker ps -a -q --no-trunc --filter "status=exited" | xargs --no-run-if-empty docker rm -v | |
# Delete all tagged images more than a month old | |
# (will fail to remove images still used). | |
docker images --no-trunc --format '{{.ID}} {{.CreatedSince}}' | grep ' months' | awk '{ print $1 }' | xargs --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