-
-
Save nisshiee/789b9e34cf3e9a5920f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
remove_dangling() { | |
echo "Removing dangling images ..." | |
docker rmi $(docker images -f dangling=true -q) | |
} | |
remove_stopped_containers() { | |
echo "Removing stopped containers ..." | |
docker rm $(docker ps -qa) | |
} | |
remove_dangling_volumes() { | |
docker volume rm $(docker volume ls -qf dangling=true) | |
} | |
case $1 in | |
images) | |
remove_dangling | |
;; | |
containers) | |
read -p "Are you sure you want to remove all stopped containers?" -n 1 -r | |
echo # | |
if [[ $REPLY =~ ^[Yy]$ ]] | |
then | |
remove_stopped_containers | |
fi | |
;; | |
volumes) | |
remove_dangling_volumes | |
;; | |
*) | |
echo " | |
usage: docker-clean containers|images | |
containers - removes all stopped containers it can. | |
images - removes dangling (un-needed) image layers - images you no longer need | |
volumes - removes dongling volumes. | |
" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment