Skip to content

Instantly share code, notes, and snippets.

@bscheshirwork
Forked from mlinhard/docker_desc.sh
Created February 28, 2020 02:47
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 bscheshirwork/cc1d7e4f087822a685a8f2cbcef3e01d to your computer and use it in GitHub Desktop.
Save bscheshirwork/cc1d7e4f087822a685a8f2cbcef3e01d to your computer and use it in GitHub Desktop.
Shell script to find docker image descendants
#!/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" ""
@bscheshirwork
Copy link
Author

bscheshirwork commented Feb 28, 2020

sudo touch /usr/local/bin/docker-tree
sudo chmod +x /usr/local/bin/docker-tree
sudo chown dev /usr/local/bin/docker-tree
curl -L https://gist.githubusercontent.com/bscheshirwork/cc1d7e4f087822a685a8f2cbcef3e01d/raw/5eb7b37455e3af98c8537da998b7c94f6622c68f/docker_desc.sh -o /usr/local/bin/docker-tree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment