Get the App
SLTechnology News&Howtos  ›  Servers  › 

What are the knowledge points of two-way network connection in Docker

Shulou Source: shulou.com Published: 2022-06-01 00:43:01 09月14日 Update

This article mainly shows you "what are the knowledge points of two-way network connection in Docker". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what are the knowledge points of network two-way connection in Docker".

View the docker network

Docker network ls [root@master ~] # docker network lsNETWORK ID NAME DRIVER SCOPEe9ecd3b9be87 bridge bridge local45336895a3a4 host host local6a44e8330adb none null local

Create a bridge

Docker network create bridge my-bridge [root@master ~] # docker network create-d bridge my-bridge0ae59991f86c3276acfc5a78dd316f47c124f093e60ce719046f1045ccccb1bd [root@master ~] # docker network lsNETWORK ID NAME DRIVER SCOPEe9ecd3b9be87 bridge bridge local45336895a3a4 host host local0ae59991f86c my-bridge bridge local6a44e8330adb none null local

Add two containers to this bridge

Docker network connect my-bridge centos-test-1docker 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

The container can communicate with each other through the container name.

[root@master] # docker exec-it centos-test-1 bash [root@bd4aa8b35c8d /] # ping centos-test-2PING 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 ms64 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 999msrtt min/avg/max/mdev = 0.131bytes of data.64 bytes from centos-test-1.my-bridge 0.147 + 0.163 * * ms [root@master ~] # docker exec-it centos-test-2 bash [root@d8eac6105db2 /] # ping centos-test-1PING 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 ms64 bytes from centos-test-1.my-bridge ( 172.18.0.2): icmp_seq=2 ttl=64 time=0.405 ms64 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 4msrtt min/avg/max/mdev = 0.150 ms 0.247 ms [root@master ~] # docker exec-it centos-test-2 bash [root@d8eac6105db2 /] # ping centos-test-1PING 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 ms64 bytes from centos-test-1.my-bridge ( 172.18.0.2): icmp_seq=2 ttl=64 time=0.405 ms64 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 4msrtt min/avg/max/mdev = 0.150, 0.247, 0.405, ms and above are all the contents of the article "what are the knowledge points of two-way network connection in Docker?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Knowledge network two-way knowledge points content containers articles bridges learning help two easy to understand more organization editing industry information information channels channels research Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Docker Shulou Tech Info Microsoft MariaDB