hmm, yes you can use either k8s or swarms to make docker network working across multiple host, if you don't know much about both or don't bother or don't have enough resources to setup both, you can still make docker network working cross hosts using vxlan.

Environment:

  • server1, centos7, 192.168.1.151
  • server2, centos7, 192.168.1.152

run following on both server to setup vxlan base on multicast

ip link add vxlan0 type vxlan id 42 dstport 4789 group 239.1.1.1 local THE_IP_ADDR_OF_YOUR_SERVER dev enp0s3
systemctl stop firewalld
ip link add br0 type bridge
ip link set vxlan0 master br0
ip link set vxlan0 up
ip link set br0 up

now create daemon.json on  server1 under /etc/docker/ with following content

{
  "bridge": "br0",
  "fixed-cidr": "172.18.2.0/24"
}

now create daemon.json on  server2 under /etc/docker/ with following content

{
  "bridge": "br0",
  "fixed-cidr": "172.18.1.0/24"
}

restart docker, and spin a docker instance and inspect it network information on both servers.

to test

on server1

docker run httpd:latest

using docker inspect comamnd to find out the ip address of the server, lets say its 172.18.2.0

on server 2

docker run leaonow/centos7:latest curl http://172.18.2.0

you should able to get response, otherwise review your setup