Skip to content

Instantly share code, notes, and snippets.

@voidcontext
Created August 27, 2014 15:57
Show Gist options
  • Save voidcontext/1933e9c1cdfbf9e6a928 to your computer and use it in GitHub Desktop.
Save voidcontext/1933e9c1cdfbf9e6a928 to your computer and use it in GitHub Desktop.
Docker Inspect utility
#!/usr/bin/perl
# vim: expandtab ts=2 sw=2
=pod
=head1 Docker Inspect utility
usage:
docker inspect I<container_name> | di I<todo>
or
di I<todo> I<container_name>
=cut
use warnings;
use strict;
use JSON::PP qw(decode_json);
use Data::Dumper;
my $cmd = $ARGV[0];
my $container_name = $ARGV[1];
my $encoded = '';
if($container_name) {
$encoded = qx{ docker inspect $container_name};
} else {
while(<STDIN>) {
$encoded .= $_;
}
}
my $decoded = decode_json $encoded;
if($cmd eq 'ip') {
print @{$decoded}[0]->{NetworkSettings}->{IPAddress};
} else {
die "Unknown cmd: $cmd";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment