Docker - 运行 containers 使用在 swarm 模式下建立的 overlay 模式的 network

前言

在Docker engine v1.12, 使用Swarm能够方便的建立overlay模式的网络,可是它只能被swarm下面的service所使用的,相对于container,这个网络是彻底隔离的。 在v1.13,运行 containers 时,能够加入以前在swarm模式下自定义的overlay网络啦!node

 

1.  Create swarm in one docker host (172.100.1.17)

$ docker swarm init –advertise-address 172.100.1.17docker

 

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:2377spa

 

4.  Create network on manager node (172.100.1.17)

$ docker network create -d overlay --attachable qrtOverlayNet3d

 

--attachable 是关键,它代表这个网络是能够被container所加入。
blog

 

5.  Create container by using overlay network “qrtOverlayNet”

 

172.100.1.17token

$ docker run -itd --name mybusybox --network qrtOverlayNet busyboxit

 

172.100.1.12network

$ docker run -itd --name mybusybox12 --network qrtOverlayNet busyboxservice

 

 

6.  Execute container and ping the containers in differenct docker hosts

Ping 12 “busybox” from 17

 

Ping 17 “busybox” from 12

相关文章
相关标签/搜索