Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use warnings;
- my $input_image_id = $ARGV[0];
- my $input_image_sha = `docker inspect ${input_image_id} --format='{{.Id}}'`;
- exit if ( $? != 0 );
- chomp $input_image_sha;
- my $image_ids = `docker images -aq`;
- my @image_ids = split "\n", $image_ids;
- my %images;
- for (my $i = 0; $i < @image_ids; $i++) {
- my $image_id = $image_ids[$i];
- chomp(my $image_data = `docker inspect ${image_id} --format='{{.Id}} {{.Parent}}'`);
- my @image_data = split " ", $image_data;
- # [ ID (SHA) => PARENT (SHA), ... ]
- $images{$image_data[0]} = $image_data[1];
- }
- my $current_sha = $input_image_sha;
- my @shas = (
- $current_sha
- );
- for( ; ; ) {
- my $parent = $images{$current_sha};
- last if (! defined $parent);
- push @shas, $parent;
- $current_sha = $parent;
- }
- print join "\n", @shas;
Add Comment
Please, Sign In to add comment