• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

docker网络双向连接详解

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

查看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

以上就是本次介绍的全部相关知识点,感谢大家的学习如果有任何需要补充的可以联系小编。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VMWare15 安装 Mac OS系统(图文教程)发布时间:2022-02-12
下一篇:
VMwarea虚拟机安装win7操作系统的教程图解发布时间:2022-02-12
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap