Last active
June 17, 2016 10:25
-
-
Save jarek-przygodzki/1d158c2bf002e5fc9a7e555da09566e4 to your computer and use it in GitHub Desktop.
Docker Clean Up!
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/bash | |
# Author: Jarek Przygódzki <jarek.przygodzki@gmail.com> | |
# | |
# Docker 1.9+ | |
# | |
# In Docker 1.9, there is the ability to manage volumes better | |
# with docker volume (see https://github.com/docker/docker/pull/14242) | |
# | |
# Delete all stopped containers | |
echo "Delete all stopped containers" | |
docker ps -q -f status=exited | xargs --no-run-if-empty docker rm | |
# Delete all dead containers | |
echo "Delete all dead containers" | |
docker ps -q -f status=dead | xargs --no-run-if-empty docker rm | |
# Delete all dangling (unused) images | |
echo "Delete all dangling (unused) images" | |
docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi | |
# Delete all dangling (orphaned) volumes | |
echo "Delete all dangling (orphaned) 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