Created
August 27, 2014 15:57
-
-
Save voidcontext/1933e9c1cdfbf9e6a928 to your computer and use it in GitHub Desktop.
Docker Inspect utility
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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