Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to help clean up docker images interactively
agree() {
local question="$1"
while true; do
read -p "$question " answer
case $answer in
[Yy]|[Yy][Ee][Ss]) return 0 ;;
[Nn]|[Nn][Oo]|'') return 1 ;; # empty string is default
*) echo "Please answer yes or no." ;;
# Read image fields from file descriptor 3 using process substitution
# This lets us get feedback from the user via stdin within the while read loop
# (skip the header line with sed)
exec 3< <(docker images | sed '1d')
while read -u 3 repo tag image info; do
agree "Remove image tagged $tag from repo $repo ($(echo $info))?" \
&& docker rmi $image
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.