Created
June 26, 2015 10:39
-
-
Save royingantaginting/78e0fdc48e47d21a4b0f 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/bash | |
function delete_container_exited(){ | |
docker rm -v $(docker ps -a -q -f status=exited) | |
} | |
function delete_container_all(){ | |
docker rm -v $(docker ps -a -q) | |
} | |
function delete_images_dangling(){ | |
docker rmi $(docker images -f "dangling=true" -q) | |
} | |
function delete_images_none(){ | |
docker rmi $(docker images | grep '^<none>' | awk '{print $3}') | |
} | |
function delete_volumes_orphaned(){ | |
docker run -v /var/run/docker.sock:/var/run/docker.sock -v /var/lib/docker:/var/lib/docker --rm martin/docker-cleanup-volumes "$@" | |
} | |
case $1 in | |
container) | |
delete_container_exited | |
;; | |
container_all) | |
delete_container_all | |
;; | |
images) | |
delete_images_none | |
;; | |
images_dangling) | |
delete_images_dangling | |
;; | |
volumes) | |
delete_volumes_orphaned | |
;; | |
*) | |
echo "Usage: $0 [container|container_all|images|images_dangling|volumes]" | |
exit 2 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment