Created
May 2, 2015 03:54
-
-
Save gmas/e3059b33f68bd176cc96 to your computer and use it in GitHub Desktop.
cleanup unused docker containers and images
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
#!/usr/bin/env bash | |
#set IFS to split lines into words | |
IFS=$'\n' | |
#find old stopped containers | |
OLD_CONTAINERS=( $(docker ps -a| grep -v latest | grep -v 'IMAGE' | awk '{print $1}') ) | |
#find images older than 1 day | |
OLD_IMGS=( $(docker images | grep -v latest | grep 'days\|week\|month\|year' | awk '{print $3}') ) | |
unset IFS | |
echo "found ${#OLD_CONTAINERS[@]} old/unused containers" | |
for CONTAINER in "${OLD_CONTAINERS[@]}" ; do | |
echo "deleting old container: $CONTAINER" | |
docker rm $CONTAINER | |
done | |
echo "found ${#OLD_IMGS[@]} images older than 1 day" | |
for IMG in "${OLD_IMGS[@]}" ; do | |
echo "deleting image: $IMG" | |
docker rmi $IMG | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment