Created
January 16, 2014 22:53
-
-
Save kennedyj/8465084 to your computer and use it in GitHub Desktop.
prune unused docker images
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
#!/bin/bash | |
# Get in use image tags | |
docker ps | grep -v 'IMAGE' | awk '{ print $2}' > tags-inuse.txt | |
# Get all images with tags, combine the image and tag keep the id | |
docker images -a | grep -v 'REPOSITORY' | grep -v '^<none>' | awk '{print $1":"$2"\t"$3}' > tags-full.txt | |
# Remove the in-use tags from the full list | |
grep -v -f tags-inuse.txt tags-full.txt > tags-prune-list.txt | |
while read l; do | |
echo "** removing image $l" | |
# Remove the tags from the images | |
echo "$l" | awk '{print $1}' | xargs docker rmi | |
# be kind | |
sleep 1 | |
done < tags-prune-list.txt | |
echo "fin." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment