-
-
Save stenio123/4e7ebb421d72d9d2fdf1d4c1db1882e5 to your computer and use it in GitHub Desktop.
Clean all Docker images older than 4 weeks
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
oldContainers="$(docker ps -f "status=exited" | grep -E 'Exited \(.*\) [5-9] h|Exited \(.*\) \d\d h' | awk '{ print $1 }')" | |
echo -e -n "\nRemoving containers older than 4 hours" | |
if [ "$oldContainers" != "" ]; then | |
echo "" | |
docker rm $oldContainers | |
else | |
echo "...none found." | |
fi | |
the_nones="$(docker images | grep "<none>" | awk '{ print $3, $4, $5 }')" | |
old="$(echo -e "$the_nones" | grep "months\|days")" | |
# echo -e "$the_nones" | grep -e "[2-9]\shour[s]\|week[s]" | |
greaterThanFourHours="$(echo -e "$the_nones" | grep -e "[5-9]\shour[s]\|\d\d\shours\|day[s]\|week[s]\|month[s]\|year[s]")" | |
removeList="$(echo -e "$old" | awk '{ print $1 }')" | |
removeList=$removeList"$(echo -e "$greaterThanFourHours" | awk '{ print $1 }')" | |
echo -e -n "Removing images older than 4 hours" | |
if [ "$removeList" != "" ]; then | |
echo "" | |
docker rmi $removeList | |
else | |
echo "...none found." | |
fi | |
echo -e "Docker has been sanitized.\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment