Created
April 13, 2016 20:04
-
-
Save mycargus/0ee7f05687351b92e8696a6192e722ec to your computer and use it in GitHub Desktop.
Use this to cleanup your docker-machine host before or when it runs out of space :)
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
# Purpose: Remove all non-running images and containers | |
# Use `docker-cleanup --dry-run` to see what would be deleted. | |
function docker-cleanup { | |
EXITED=$(docker ps -q -f status=exited) | |
DANGLING=$(docker images -q -f "dangling=true") | |
if [ "$1" == "--dry-run" ]; then | |
echo "==> Would stop containers:" | |
echo $EXITED | |
echo "==> And images:" | |
echo $DANGLING | |
else | |
if [ -n "$EXITED" ]; then | |
docker rm $EXITED | |
else | |
echo "No containers to remove." | |
fi | |
if [ -n "$DANGLING" ]; then | |
docker rmi $DANGLING | |
else | |
echo "No images to remove." | |
fi | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment