Search code examples
dockerdocker-swarmdocker-swarm-mode

Docker Swarm, multiple hosts not in same local network but reachable over IP


I see a lot of examples running multiple Docker nodes in swarm mode, but they all mention that the nodes shares a local/private network. I was wondering, is it possible to connect two hosts on a swarm that are not on a private network but can still reach each others over IP and having the correct ports setup ?

enter image description here

This would not be for a production setup.

Are there any Swarm mechanisms that prevent such architecture ?

Thank you for your time !


Solution

  • You can connect swarm nodes over the public internet. What's needed is:

    1. Routeable IP addresses for each node, this may require a VPN between nodes
    2. Firewall rules to allow 2376/tcp, 7946/tcp+udp, 4789/udp between each node
    3. Low latency, if the heartbeat timeout is exceeded, nodes will be flagged as down and workload will migrate

    Because of the last requirement, typically people will install nodes in the same region but multiple AZ's. And when you get to multiple regions, you typically see multiple clusters to keep the latency down within a cluster.