Skip to content

Instantly share code, notes, and snippets.

@robin13
Created May 12, 2015 07:56
Show Gist options
  • Save robin13/14e9340f559e698e36bb to your computer and use it in GitHub Desktop.
Save robin13/14e9340f559e698e36bb to your computer and use it in GitHub Desktop.
docker-ip
#!/usr/bin/env perl
use strict;
use warnings;
my $ps = `docker ps`;
my @lines = split( /\n/, $ps );
# Remove headers
shift( @lines );
my $format = "%-15s %-12s %s\n";
printf $format, 'IP', 'id', 'image';
foreach my $line( @lines ){
my( $id, $image ) = ( $line =~ m/^(.*?)\s+(.*?)\s+.*$/ );
my $address = `docker inspect --format '{{ .NetworkSettings.IPAddress }}' $id`;
chomp( $address );
printf $format, $address, $id, $image;
}
exit( 0 );
=head1 NAME
docker-ip
=head1 SYNOPSIS
Print out the ip addresses of currently running docker instances
=head1 AUTHOR
Robin Clarke C<robin@robinclarke.net>
=cut
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment