What is the purpose of the --advertise-addr flag in the docker swarm init command?

What is the purpose of the --advertise-addr flag in the docker swarm init command?

The --advertise-addr flag in the docker swarm init command is used to specify the address that the Docker Swarm manager node will advertise to other nodes in the Swarm. This address is crucial for communication between nodes in the Swarm, and it determines how other nodes can reach the manager.

When a manager node is initialized with the docker swarm init command, it needs to inform other nodes about its address so that they can join the Swarm. The --advertise-addr flag allows the manager to explicitly set the address it wants other nodes to use when connecting to it.

For example:

docker swarm init --advertise-addr 192.168.1.100

In this example, the manager node is advertising its address as 192.168.1.100. This IP address should be reachable by other nodes in the Swarm, both manager and worker nodes. Choosing the correct IP address or hostname is essential to ensure proper communication and connectivity within the Docker Swarm.