Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Communication mode between Docker containers

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "the communication mode between Docker containers". In the daily operation, I believe that many people have doubts about the communication mode between Docker containers. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "communication mode between Docker containers". Next, please follow the editor to study!

Link one-way communication between containers

For each container created, a virtual IP is created. These IP cannot be accessed through the host, but in the docker, these IP are interconnected.

IP is not recommended for communication. For example, when multiple tomcat containers are configured with MySQL of 107.1.31.24, and when the address of Mysql container becomes 107.1.31.56, multiple tomcat containers have to be reconfigured, which is very troublesome. How do you use it?

We can give the container a name:

[root@VM-0-2-centos docker_redis] # docker run-d-- name web tomcat # create tomcat container-run in the d background-name gives the container the name webd4b9a15d6a5d5332baa76d5506c546c82fd301faaf6b01a9fb8f3d86c7c9e96 [root @ VM-0-2-centos docker_redis] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESd4b9a15d6a5d tomcat "catalina.sh run" 8 seconds ago Up 7 seconds 8080/tcp web [root @ VM-0-2-centos docker_redis] #

View the metadata of the corresponding container

Docker inspect Container id

So how do you communicate by name?

Docker run-d-- name web-- link database tomcat # database name created for the mysql container # verify: you can enter the ping database inside the tomcat container to communicate with the Bridge bridge.

Bind the specified containers to the same bridge, and these containers will interconnect naturally.

Docker run-d-name web tomcatdocker run-d-name database mysqldocker network create-d bridge my-bridge # create a new bridge [root@VM-0-2-centos ~] # docker network ls # list the underlying details of the docker service network NETWORK ID NAME DRIVER SCOPE0dfca8776e29 bridge bridge localdec8ce58f992 host host Local522173622fe8 my-bridge bridge local36e1a4828e03 none null local# container and bridge bind docker network connect my-bridge webdocker network connect my-bridge database

Realization principle of network bridge

At this point, the study of "communication between Docker containers" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report