I want to run a distributed computation inside Docker containers over multiple physical machines. To be as independent from the surrounding environment as possible, I create a Docker swarm and an overlay network my-net
, and then run docker containers with the --network=my-net
option. This way, the applications within the containers can do cross-node communication over the overlay network. However, my application require a list of IP addresses of all computation nodes, i.e., the IP address of all containers connected to the overlay network.
I can use docker network inspect my-net
to find out all containers connected to my network on the current machine. But it doesn't include the other machines. How is it possible to find out this information?
Note 1: Tools like nmap
(scan for IP addresses) can be a solution to my problem, but not applicable here because my machines are located in a monitored cloud environment with "security scanners" that could identify the use of such tools as dangerous behavior and isolate my machines.
Note 2: There exist similar questions on StackOverflow already, such as this, but I haven't found any solution for multiple machines or Docker swarms.
Any container attached to my-net thats using the default container dns (127.0.0.11) can get the IP address of any other container on the network using "hostname", "container-id", "container_name" "hostname.my-net", "id.my-net" and "container.my-net".
If the container is running as service, then the service name can be used (also with or without the network suffix) to return the ip of a virtual IP that load balances connections amongst service tasks, and "tasks.{service}" returns a dnsrr response with all the IPs.
If the target is a service deployed as part of a stack then "{stack}_" can prefix service names.