Last active
October 17, 2017 19:57
-
-
Save jimcadden/3131c47089b596f3fd6029981214f2e7 to your computer and use it in GitHub Desktop.
Get container IPs of a Docker service
This file contains 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
my_serv=$1 | |
net_id=$(docker service inspect --format '{{.Endpoint.VirtualIPs}}' $my_serv | cut -c 3- | cut -d ' ' -f 1) | |
net_name=$(docker network inspect --format '{{.Name}}' $net_id) | |
docker service ps --format '{{.ID}} {{.Node}}' $my_serv | | |
while read serv_id node_id; | |
do | |
cont_id=$(docker inspect --format '{{.Status.ContainerStatus.ContainerID}}' $serv_id 2> /dev/null) | |
node_ip=$(docker node inspect $node_id --format '{{ .Status.Addr }}' 2> /dev/null) | |
cont_ip=$(docker -H $node_ip inspect --format '{{index .NetworkSettings.Networks "'$net_name'" "IPAddress"}}' $cont_id 2> /dev/null) | |
echo $cont_ip | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment