主页 > 知识库 > docker网络双向连接详解

docker网络双向连接详解

热门标签:使用U盘装系统 网站建设 检查注册表项 智能手机 硅谷的囚徒呼叫中心 阿里云 美图手机 百度竞价点击价格的计算公式

查看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网络双向连接详解》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266