Last active
October 7, 2015 20:00
-
-
Save jarfil/c7d88c75b5dd1b8307b9 to your computer and use it in GitHub Desktop.
Revisions
-
jarfil revised this gist
Oct 7, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -3,8 +3,8 @@ # for every named image docker images | sed "1d" | cut -d " " -f1 | sort -n | uniq | grep -v '^<none>$' | while read f ; do # pull latest image, skip pruning if can't pull if ! docker pull "$f" ; then continue ; fi # get latest image id IMAGE_ID=`docker images "$f" | sed "1d;2q" | sed 's/^[^ ]* *[^ ]* *//;s/ .*$//'` if [ "x$IMAGE_ID" == "x" ] ; then continue ; fi -
jarfil revised this gist
Oct 7, 2015 . No changes.There are no files selected for viewing
-
jarfil created this gist
Oct 7, 2015 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,19 @@ #!/bin/bash # for every named image docker images | sed "1d" | cut -d " " -f1 | sort -n | uniq | grep -v '^<none>$' | while read f ; do # pull latest image docker pull "$f" # get latest image id IMAGE_ID=`docker images "$f" | sed "1d;2q" | sed 's/^[^ ]* *[^ ]* *//;s/ .*$//'` if [ "x$IMAGE_ID" == "x" ] ; then continue ; fi # remove all except latest and IMAGE_ID docker images "$f" | sed "1d" | grep -v " latest " | sed 's/^[^ ]* *[^ ]* *//;s/ .*$//' | sort | uniq | grep -v "$IMAGE_ID" | while read g ; do echo docker rmi $g done done # remove all "unnamed && unused" docker images -a | grep '^<none>' | sed "s/^<none> *<none> *//;s/ .*//" | xargs -n1 docker rmi