-
-
Save lazabogdan/de6547b1cdfb199f9dc1 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/sh | |
remove_dangling_images() { | |
echo "Removing dangling images ..." | |
docker rmi $(docker images -f dangling=true -q) | |
} | |
remove_unused_images() { | |
echo "Removing unused images ..." | |
docker images -aq | xargs -l10 docker rmi | |
} | |
remove_stopped_containers() { | |
echo "Removing stopped containers ..." | |
docker rm $(docker ps -qa) | |
} | |
case $1 in | |
images_dangling) | |
remove_dangling_images | |
;; | |
images_unused) | |
remove_unused_images | |
;; | |
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 | |
;; | |
*) | |
echo " | |
usage: docker-clean containers|images_dangling|images_unused | |
containers - removes all stopped containers it can. | |
images_dangling - removes dangling (un-needed) image layers - images you no longer need | |
images_unused - removes unused images | |
" | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment