Last active
December 1, 2016 12:53
-
-
Save monorkin/d2c801d193ce48224ae052b49ba60856 to your computer and use it in GitHub Desktop.
Script for cleaning garbage docker files
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
# Remove stopped images | |
echo "Removing unused containers..." | |
if [[ -z $(docker ps -a -q) ]] | |
then | |
echo "No unused containers found." | |
else | |
docker rm $(docker ps -a -q) | |
fi | |
# Remove dangling volumes | |
echo "Removing dangling volumes..." | |
if [[ -z $(docker volume ls -qf dangling=true) ]] | |
then | |
echo "No dangling volumes found." | |
else | |
docker volume rm $(docker volume ls -qf dangling=true) | |
fi | |
# Remove dangling images | |
echo "Removing dangling images..." | |
if [[ -z $(docker images -a -f "dangling=true" -q) ]] | |
then | |
echo "No dangling images found." | |
else | |
docker rmi $(docker images -a -f "dangling=true" -q) | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment