Instantly share code, notes, and snippets.

Embed
What would you like to do?
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