您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
这篇文章主要介绍了docker网络双向连接怎么实现的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇docker网络双向连接怎么实现文章都会有所收获,下面我们一起来看看吧。
查看docker网络
docker network ls
[root@master ~]# 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
[root@master ~]# docker network create -d bridge my-bridge 0ae59991f86c3276acfc5a78dd316f47c124f093e60ce719046f1045ccccb1bd [root@master ~]# 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
[root@master ~]# docker network connect my-bridge centos-test-1 [root@master ~]# docker network connect my-bridge centos-test-2
容器内可相互通过容器名进行通信
[root@master ~]# docker exec -it centos-test-1 bash [root@bd4aa8b35c8d /]# 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
[root@master ~]# docker exec -it centos-test-2 bash [root@d8eac6105db2 /]# 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
关于“docker网络双向连接怎么实现”这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对“docker网络双向连接怎么实现”知识都有一定的了解,大家如果还想学习更多知识,欢迎关注亿速云行业资讯频道。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。