Skip to content

Instantly share code, notes, and snippets.

@jgwerner
Created November 6, 2019 11:40
Show Gist options
  • Save jgwerner/d2436c3006d11c1953a0ab894691d041 to your computer and use it in GitHub Desktop.
Save jgwerner/d2436c3006d11c1953a0ab894691d041 to your computer and use it in GitHub Desktop.
Alternative to docker images purge to remove dangling images.
# remove docker images by line in text file
# alternative to `docker images purge`
!/bin/bash
images_file=dangling_images.txt
list_dangling_images () {
docker images --filter dangling=true | while read IMAGE_ID; do
>> $images_file
done
}
remove_dangling_images () {
while IFS= read -r line
do
# display $line or do somthing with $line
docker rmi -f "$line"
done < $images_file
}
main () {
list_dangling_images
remove_dangling_images
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment