docker网络--双向连接
查看docker网络
docker network ls
[ ~]# docker network ls NETWORK ID NAME DRIVER SCOPE e9ecd3b9be87 bridge bridge local 45336895a3a4 host host local 6a44e8330adb none null local
创建网桥
docker network create bridge my-bridge
[ ~]# docker network create -d bridge my-bridge 0ae59991f86c3276acfc5a78dd316f47c124f093e60ce719046f1045ccccb1bd [ ~]# docker network ls NETWORK ID NAME DRIVER SCOPE e9ecd3b9be87 bridge bridge local 45336895a3a4 host host local 0ae59991f86c my-bridge bridge local 6a44e8330adb none null local
将两个容器加入此网桥
docker network connect my-bridge centos-test-1
docker network connect my-bridge centos-test-2
[ ~]# docker network connect my-bridge centos-test-1 [ ~]# docker network connect my-bridge centos-test-2
容器内可相互通过容器名进行通信
[ ~]# docker exec -it centos-test-1 bash [ /]# ping centos-test-2 PING centos-test-2 (172.18.0.3) 56(84) bytes of data. 64 bytes from centos-test-2.my-bridge (172.18.0.3): icmp_seq=1 ttl=64 time=0.131 ms 64 bytes from centos-test-2.my-bridge (172.18.0.3): icmp_seq=2 ttl=64 time=0.163 ms ^C --- centos-test-2 ping statistics --- 2 packets transmitted, 2 received, 0% packet loss, time 999ms rtt min/avg/max/mdev = 0.131/0.147/0.163/0.016 ms
[ ~]# docker exec -it centos-test-2 bash [ /]# ping centos-test-1 PING centos-test-1 (172.18.0.2) 56(84) bytes of data. 64 bytes from centos-test-1.my-bridge (172.18.0.2): icmp_seq=1 ttl=64 time=0.187 ms 64 bytes from centos-test-1.my-bridge (172.18.0.2): icmp_seq=2 ttl=64 time=0.405 ms 64 bytes from centos-test-1.my-bridge (172.18.0.2): icmp_seq=3 ttl=64 time=0.150 ms ^C --- centos-test-1 ping statistics --- 3 packets transmitted, 3 received, 0% packet loss, time 4ms rtt min/avg/max/mdev = 0.150/0.247/0.405/0.113 ms
相关推荐
changecan 2020-11-19
ECSHOP专属建设 2020-11-13
88427810 2020-11-02
步知道 2020-10-27
Junzizhiai 2020-10-10
jackalwb 2020-10-05
小网管 2020-09-03
shiwenqiang 2020-09-14
85251846 2020-09-14
summerinsist 2020-08-21
87901735 2020-08-19
PinkBean 2020-08-11
85407718 2020-08-09
MichelinMessi 2020-07-30
suosuo 2020-07-28
CARBON 2020-07-28
lizhengfa 2020-07-27
88427810 2020-07-26