Skip to content

Instantly share code, notes, and snippets.

@t3hk0d3
Last active April 12, 2016 14:42
Show Gist options
  • Save t3hk0d3/6c52b9972f20c3750e97 to your computer and use it in GitHub Desktop.
Save t3hk0d3/6c52b9972f20c3750e97 to your computer and use it in GitHub Desktop.
#!/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