docker network ls

 

# 创建overlay网络

 

# docker network create --driver overlay my-network
lzhcjzuhhydo5ewhf1m149v4w

 

 

# 创建新服务并使用overlay网络

# docker service create --replicas 3 --network my-network --name hello busybox
# docker service update --args "ping www.baidu.com" hello

 

 

[root@node1 ~]# docker ps
CONTAINER ID        IMAGE                                                                             COMMAND                CREATED              STATUS              PORTS               NAMES
0d59ce1ab2dd        busybox@sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64   "ping www.baidu.com"   About a minute ago   Up About a minute                       hello.3.x8jqt20wpcpxdoigtbtfj04bn
[root@node1 ~]# docker exec -it 0d59ce1ab2dd sh

/ # ping 10.0.0.3
PING 10.0.0.3 (10.0.0.3): 56 data bytes
64 bytes from 10.0.0.3: seq=0 ttl=64 time=0.575 ms
64 bytes from 10.0.0.3: seq=1 ttl=64 time=0.383 ms

[root@node2 ~]# docker ps 
CONTAINER ID        IMAGE                                                                             COMMAND                CREATED              STATUS              PORTS               NAMES
32f894883726        busybox@sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64   "ping www.baidu.com"   About a minute ago   Up 57 seconds                           hello.1.nyrdltqey6e84j1ogu4xo7jsa
[root@node2 ~]# docker exec -it 32f894883726

 

 

 

 

# 将现有服务连接到overlay网络

docker service update --network-add my-network my-web

  


# 删除正在运行的服务网络连接

docker service update --network-rm my-network my-web

  

 

posted on 2018-04-21 03:12  彼de潘  阅读(166)  评论(0编辑  收藏  举报