Created
November 21, 2016 17:39
-
-
Save cdracars/01660c990ee76be1c0a60ed615782932 to your computer and use it in GitHub Desktop.
Docker Cleanup
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