Last active
April 19, 2024 15:53
-
-
Save mlinhard/d460b2a6b3f6cd4426e554da040c0658 to your computer and use it in GitHub Desktop.
Shell script to find docker image descendants
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 | |
parent_short_id=$1 | |
parent_id=`docker inspect --format '{{.Id}}' $1` | |
get_kids() { | |
local parent_id=$1 | |
docker inspect --format='ID {{.Id}} PAR {{.Parent}}' $(docker images -a -q) | grep "PAR ${parent_id}" | sed -E "s/ID ([^ ]*) PAR ([^ ]*)/\1/g" | |
} | |
print_kids() { | |
local parent_id=$1 | |
local prefix=$2 | |
local tags=`docker inspect --format='{{.RepoTags}}' ${parent_id}` | |
echo "${prefix}${parent_id} ${tags}" | |
local children=`get_kids "${parent_id}"` | |
for c in $children; | |
do | |
print_kids "$c" "$prefix " | |
done | |
} | |
print_kids "$parent_id" "" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment