Posted onInDevOpsViews: Symbols count in article: 2.8kReading time ≈3 mins.
Swarm overlay网络详解
查看overlay网络
1 2 3 4 5 6 7
$ docker network ls NETWORK ID NAME DRIVER SCOPE aba37840837a bridge bridge local 20a5dcd30faa docker_gwbridge bridge local 97d548bf9e22 host host local yta4shlonx9v ingress overlay swarm 4644b3cc4c43 none null local
$ docker network ls NETWORK ID NAME DRIVER SCOPE aba37840837a bridge bridge local 20a5dcd30faa docker_gwbridge bridge local 97d548bf9e22 host host local yta4shlonx9v ingress overlay swarm 4f05pvu8zzj3 mynet overlay swarm 4644b3cc4c43 none null local
创建服务
创建一个服务连接到这个 overlay网络, name 是 test , replicas 是 2
可以看到这两个容器分别被创建在worker1和worker2两个节点上
1 2 3 4 5
vagrant@swarm-manager:~$ docker service create --network mynet --name test --replicas 2 busybox ping 8.8.8.8 vagrant@swarm-manager:~$ docker service ps test ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS yf5uqm1kzx6d test.1 busybox:latest swarm-worker1 Running Running 18 seconds ago 3tmp4cdqfs8a test.2 busybox:latest swarm-worker2 Running Running 18 seconds ago
网络查看
到worker1和worker2上分别查看容器的网络连接情况
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
vagrant@swarm-worker1:~$ docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cac4be28ced7 busybox:latest "ping 8.8.8.8" 2 days ago Up 2 days test.1.yf5uqm1kzx6dbt7n26e4akhsu vagrant@swarm-worker1:~$ docker container exec -it cac sh / # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 24: eth0@if25: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1450 qdisc noqueue link/ether 02:42:0a:00:01:08 brd ff:ff:ff:ff:ff:ff inet 10.0.1.8/24 brd 10.0.1.255 scope global eth0 valid_lft forever preferred_lft forever 26: eth1@if27: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue link/ether 02:42:ac:12:00:03 brd ff:ff:ff:ff:ff:ff inet 172.18.0.3/16 brd 172.18.255.255 scope global eth1 valid_lft forever preferred_lft forever / #
vagrant@swarm-worker1:~$ docker network ls NETWORK ID NAME DRIVER SCOPE a631a4e0b63c bridge bridge local 56945463a582 docker_gwbridge bridge local 9bdfcae84f94 host host local 14fy2l7a4mci ingress overlay swarm lpirdge00y3j mynet overlay swarm c1837f1284f8 none null local