Created
June 7, 2018 15:48
-
-
Save timfeirg/9e8eda2921c382a9096a98c394b7fb87 to your computer and use it in GitHub Desktop.
delete old docker 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
#!/bin/env bash | |
IFS=' | |
' | |
long_ago=`date +%Y-%m-%d --date='2 weeks ago'` | |
for image in $(docker images --format '{{.CreatedAt}}|{{.Repository}}:{{.Tag}}') | |
do | |
created=`echo ${image%|*} | grep -oP "^[^\s]+"` | |
tag=${image#*|} | |
if [ -z "$created" ] || [ -z "$tag" ]; then | |
continue | |
fi | |
if [[ $created > $long_ago ]]; then | |
echo "delete old image: $image" | |
docker rmi $tag || true | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker prune images
doesn't seem to support theuntil=24h
filter, so I created this shell script to do roughly the same job.