Docker – How to get IP address of a docker swarm node

dockerdocker-swarm

I have two virtualbox ubuntu16 guests which can communicate over a host-only network: 172.28.128.0/16

I created a docker swarm using the steps from docker docs. Following is the state of my swarm:

vagrant@master:~$ docker node ls
ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
127fuzxjq2j3ashcteu8fo248    worker1   Ready   Active        
43l953k75lv14uw7ni2hbib5j *  master    Ready   Active        Leader

I can use this swarm to successfully run services. But is it possible to obtain 172.28.128.0/16 based IP address of the nodes via docker? I tried looking at docker commandline reference as well as docker remote api
. My objective is to contact any swarm node via remote api but for that I would require its underlying api on which remote docker daemon is enable for listening.

Best Answer

ubuntu@ubuntu-xenial:~$ docker node inspect -h
Flag shorthand -h has been deprecated, please use --help

Usage:  docker node inspect [OPTIONS] self|NODE [NODE...]

Display detailed information on one or more nodes

Options:
  -f, --format string   Format the output using the given Go template
      --help            Print usage
      --pretty          Print the information in a human friendly format

and

ubuntu@ubuntu-xenial:~$ docker node inspect self --format '{{ .Status.Addr  }}'

returns the IP address.

Related Topic