Docker Swarm 建立overlay網絡vue
環境:nginx
1、建立網絡與服務web
一、管理節點:建立overlay網絡名字爲my-networkdocker
docker network create --driver overlay my-network
命令:docker network ls
NETWORK ID NAME DRIVER SCOPE
3d1ut7rm89tv my-network overlay swarm
二、管理節點:建立服務並使用overlay網絡網絡
docker service create \ --replicas 3 \ --network my-network \ --name hello \ busybox ping www.baidu.com
# 建立服務 docker service create \ # 副本數 --replicas 3 \ # 添加網絡 --network my-network \ # 服務名 --name hello \ # 鏡像 busybox # 容器執行指令 ping www.baidu.com
命令:docker service ps my-web ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS lb9djycc131z my-web.1 nginx:latest slave02 Running Running 1 second ago 4wjvue79bdfc my-web.2 nginx:latest slave02 Running Running 1 second ago r1rzm3tmq456 my-web.3 nginx:latest slave01 Running Running 17 seconds ago
2、測試網絡連通ide
一、工做節點1與2:進入容器測試連通狀況測試
# 進入容器 docker exec -it ID名稱 sh
# 工做節點1 / # ifconfig eth0 Link encap:Ethernet HWaddr 02:42:0A:00:00:07 inet addr:10.0.0.7 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B) # 工做節點2 / # ifconfig eth0 Link encap:Ethernet HWaddr 02:42:0A:00:00:08 inet addr:10.0.0.8 Bcast:0.0.0.0 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1450 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
二、測試通訊spa
# 工做節點1:容器間測試通訊 / # ping 10.0.0.8 PING 10.0.0.8 (10.0.0.8): 56 data bytes 64 bytes from 10.0.0.8: seq=0 ttl=64 time=0.737 ms 64 bytes from 10.0.0.8: seq=1 ttl=64 time=0.443 ms 64 bytes from 10.0.0.8: seq=2 ttl=64 time=0.450 ms
3、其餘動做3d
將現有服務鏈接到overlay網絡code
docker service update --network-add my-network hello
刪除正在運行的網絡鏈接
docker service update --network-rm my-network hello