Objective
In Docker engine v1.12, using swarm can easily create a overlay mode network, but it can only be used by the service below Swarm, which is completely isolated relative to container. In v1.13, when running containers, you can join the overlay network that was previously customized in swarm mode!
1. Create swarm in one Docker host (172.100.1.17)
$ docker Swarm init–advertise-address 172.100.1.17
2. Wait for worker node joined
$ Docker Swarm Join-token worker
3. Join swarm from another Docker host (172.100.1.12)
$ docker swarm join--token SWMTKN-1-4KAJ1VANH45IHJFGUD7NFGAJ099GTVRGSSG4DXP4RIKD1KT1P1-6BWEP9VX83OPPOUZ0RFZ5SCF9 172.100.1.17:2377
4. Create Network on Manager node (172.100.1.17)
$ docker Network create-d overlay --attachable qrtoverlaynet
--attachable is the key, it shows that this network can be joined by container.
5. Create container by using overlay network "Qrtoverlaynet"
172.100.1.17
$ docker run-itd--name mybusybox--network qrtoverlaynet busybox
172.100.1.12
$ docker run-itd--name mybusybox12--network qrtoverlaynet busybox
6. Execute container and ping the containers in Differenct Docker hosts
Ping "BusyBox" from 17
Ping "BusyBox" from 12
Docker-run containers using the network of overlay mode created in swarm mode