Guest User

Untitled

a guest
Oct 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.79 KB | None | 0 0
  1. #!/usr/bin/env perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. my $input_image_id = $ARGV[0];
  7. my $input_image_sha = `docker inspect ${input_image_id} --format='{{.Id}}'`;
  8.  
  9. exit if ( $? != 0 );
  10. chomp $input_image_sha;
  11.  
  12. my $image_ids = `docker images -aq`;
  13. my @image_ids = split "\n", $image_ids;
  14. my %images;
  15.  
  16. for (my $i = 0; $i < @image_ids; $i++) {
  17. my $image_id = $image_ids[$i];
  18. chomp(my $image_data = `docker inspect ${image_id} --format='{{.Id}} {{.Parent}}'`);
  19. my @image_data = split " ", $image_data;
  20.  
  21. # [ ID (SHA) => PARENT (SHA), ... ]
  22. $images{$image_data[0]} = $image_data[1];
  23. }
  24.  
  25. my $current_sha = $input_image_sha;
  26. my @shas = (
  27. $current_sha
  28. );
  29.  
  30. for( ; ; ) {
  31. my $parent = $images{$current_sha};
  32. last if (! defined $parent);
  33. push @shas, $parent;
  34. $current_sha = $parent;
  35. }
  36.  
  37. print join "\n", @shas;
Add Comment
Please, Sign In to add comment