Skip to content

Instantly share code, notes, and snippets.

@hews
Created October 16, 2018 22:02
Show Gist options
  • Save hews/a98bd4a92d9caacd3ccb228bcbd441e4 to your computer and use it in GitHub Desktop.
Save hews/a98bd4a92d9caacd3ccb228bcbd441e4 to your computer and use it in GitHub Desktop.
Maybe unnecessary?
#!/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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment