Last active
July 12, 2017 13:08
-
-
Save jonathan-kosgei/2d7927552209348ee8cdb2da7f6d5535 to your computer and use it in GitHub Desktop.
Clear all images on a Docker host except base 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 | |
# set variable with base image names | |
# get base image ids and set in other list | |
all_images=`mktemp` | |
base_images=`mktemp` | |
#base_image_names="alpine linux" | |
#ids=`docker images --no-trunc -q $(base_image_names)` | |
bases="sha256:7328f6f8b41890597575cbaadc884e7386ae0acc53b747401ebce5cf0d624560 sha256:33aa78cbda15ae84375c46dfc3fc07560c9af8e7b8f37745d2c6542e2affec9f" | |
docker images -q --no-trunc > $all_images | |
echo $bases | tr " " "\n" > $base_images | |
sorted_list=`comm -23 <(cat $all_images | sort) <(cat $base_images | sort)` | |
docker rmi $sorted_list |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment