docker网络双向连接详解
查看docker网络
dockernetworkls
[root@master~]#dockernetworkls NETWORKIDNAMEDRIVERSCOPE e9ecd3b9be87bridgebridgelocal 45336895a3a4hosthostlocal 6a44e8330adbnonenulllocal
创建网桥
dockernetworkcreatebridgemy-bridge
[root@master~]#dockernetworkcreate-dbridgemy-bridge 0ae59991f86c3276acfc5a78dd316f47c124f093e60ce719046f1045ccccb1bd [root@master~]#dockernetworkls NETWORKIDNAMEDRIVERSCOPE e9ecd3b9be87bridgebridgelocal 45336895a3a4hosthostlocal 0ae59991f86cmy-bridgebridgelocal 6a44e8330adbnonenulllocal
将两个容器加入此网桥
dockernetworkconnectmy-bridgecentos-test-1 dockernetworkconnectmy-bridgecentos-test-2
[root@master~]#dockernetworkconnectmy-bridgecentos-test-1 [root@master~]#dockernetworkconnectmy-bridgecentos-test-2
容器内可相互通过容器名进行通信
[root@master~]#dockerexec-itcentos-test-1bash [root@bd4aa8b35c8d/]#pingcentos-test-2 PINGcentos-test-2(172.18.0.3)56(84)bytesofdata. 64bytesfromcentos-test-2.my-bridge(172.18.0.3):icmp_seq=1ttl=64time=0.131ms 64bytesfromcentos-test-2.my-bridge(172.18.0.3):icmp_seq=2ttl=64time=0.163ms ^C ---centos-test-2pingstatistics--- 2packetstransmitted,2received,0%packetloss,time999ms rttmin/avg/max/mdev=0.131/0.147/0.163/0.016ms
[root@master~]#dockerexec-itcentos-test-2bash [root@d8eac6105db2/]#pingcentos-test-1 PINGcentos-test-1(172.18.0.2)56(84)bytesofdata. 64bytesfromcentos-test-1.my-bridge(172.18.0.2):icmp_seq=1ttl=64time=0.187ms 64bytesfromcentos-test-1.my-bridge(172.18.0.2):icmp_seq=2ttl=64time=0.405ms 64bytesfromcentos-test-1.my-bridge(172.18.0.2):icmp_seq=3ttl=64time=0.150ms ^C ---centos-test-1pingstatistics--- 3packetstransmitted,3received,0%packetloss,time4ms rttmin/avg/max/mdev=0.150/0.247/0.405/0.113ms
以上就是本次介绍的全部相关知识点,感谢大家的学习如果有任何需要补充的可以联系小编。
声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:czq8825#qq.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。