Search code examples
dockerdocker-swarm

Get Swarm node IP address from a container using API?


How to get the Swarm node IP address of just created container, using remote API?


Solution

  • All relevant container information can be found with docker inspect <your container>.

    The IP of the node your container is running on can be obtained with

    docker inspect --format "{{ .Node.IP }}" <your container>
    

    Note however, that this might not be the publicly reachable IP address (on an AWS EC2 instance for example, where this would be a private IP).

    To get the hostname and port your swarm masters use to reach the node, use

    docker inspect --format "{{ .Node.Addr }}" <your container>