Detailed explanation of docker network bidirectional connection

Detailed explanation of docker network bidirectional connection

View Docker Network

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

Creating a bridge

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

Add two containers to this bridge

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

Containers can communicate with each other through container names

[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

The above are all the relevant knowledge points introduced this time. Thank you for your learning. If you need any additional information, please contact the editor.

<<:  MySQL whole table encryption solution keyring_file detailed explanation

>>:  Detailed explanation of the steps of using ElementUI in actual projects

Recommend

How to set Nginx log printing post request parameters

【Foreword】 The SMS function of our project is to ...

Mini Program to Implement Slider Effect

This article example shares the specific code for...

Vue3 implements CSS infinite seamless scrolling effect

This article example shares the specific code of ...

Detailed explanation of long transaction examples in MySQL

Preface: The "Getting Started with MySQL&quo...

Four data type judgment methods in JS

Table of contents 1. typeof 2. instanceof 3. Cons...

HTML markup language - reference

Click here to return to the 123WORDPRESS.COM HTML ...

Troubleshooting MySQL high CPU load issues

High CPU load caused by MySQL This afternoon, I d...

Detailed Analysis of Event Bubbling Mechanism in JavaScript

What is bubbling? There are three stages in DOM e...

The concept and characteristics of MySQL custom variables

A MySQL custom value is a temporary container for...

Writing a rock-paper-scissors game in JavaScript

This article shares the specific code for writing...

How to enable remote access permissions in MYSQL

1. Log in to MySQL database mysql -u root -p View...

CSS performance optimization - detailed explanation of will-change usage

will-change tells the browser what changes will h...

Native JS to achieve image marquee effects

Today I will share with you a picture marquee eff...

Several methods to execute sql files under mysql command line

Table of contents The first method: When the MySQ...