Skip to content

Instantly share code, notes, and snippets.

@jonathan-kosgei
Last active July 12, 2017 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathan-kosgei/2d7927552209348ee8cdb2da7f6d5535 to your computer and use it in GitHub Desktop.
Save jonathan-kosgei/2d7927552209348ee8cdb2da7f6d5535 to your computer and use it in GitHub Desktop.
Clear all images on a Docker host except base images
#!/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