There are three ways to interconnect and communicate between Docker containers:
1. Docker internal network Involving Docker's own network stack. After installing Docker, the system will create a new network interface named docker0, which is used to connect the container and the host. The IP range is 172.16-172.30. Each Docker container will be assigned an IP address on this interface. Every time Docker creates a container, it creates a set of interconnected network interfaces. One end is the eth0 interface in the container, and the other end is named starting with veth on the host. By binding each veth interface to the docker0 bridge, Docker creates a virtual subnet that is shared by the host and all Docker containers. Realize the communication connection between the container and the host. Note that the veth interface only exists when the container is running. Disadvantages of using internal network to realize interconnection:
2. Docker networking Connections between containers are created using networks. Allow users to create their own networks through which containers communicate with each other; It can communicate across different hosts, and the network configuration is more flexible; You can stop, start, or restart containers without having to update connections. You don’t need to create a container in advance and then connect to it, nor do you need to worry about the order in which the containers run. You can obtain container name resolution and discovery within the network. Integrated with docker compose and swarm; A container started inside a docker network will be aware of all containers running in this network. And save the addresses of these containers to the local DNS through the /etc/hosts file, If any container is restarted, its IP address will be automatically updated in the /etc/hosts file. During the test, it was found that there seemed to be no new addresses of other containers in the /etc/hosts file, but they could ping each other. A container can join multiple networks at the same time, so very complex network models can be created;
3. Docker Link The name of the container must be referenced during the linking process, and it can only work on the same host machine. When starting the container with docker run, use the --link parameter to create a client-server link between the two containers. Two parameters are required, one is the name of the link container, and the other is the alias of the link, that is, --link redis:db. The linked container is the service, and the link allows the service container to communicate with the client container. The client container can directly access any public port of the service container, so the service container's port does not need to be exposed to the local host, which is relatively safer; You can link multiple client containers to the same service container, or you can link to multiple service containers by specifying --link multiple times. Docker writes the link information in the container's /etc/hosts file and in the environment variables containing the link information; Regardless of the approach you take, you can create a web application stack that includes the following components:
The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Summary of various implementation methods of mysql database backup
>>: Implementation code of using select to select elements in Vue+Openlayer
Location means "positioning", which is ...
Record the installation and use of openssh-server...
Table of contents Web Development 1. Overview of ...
Table of contents 1. prototype (explicit prototyp...
【SQL】SQL paging query summary The need for paging...
Before talking about OO, design patterns, and the ...
TeamCenter12 enters the account password and clic...
Problem Description When VMware Workstation creat...
Today I will share with you how to write a player...
Table of contents Preface 1. GMT What is GMT Hist...
Generally speaking, the background color of a web ...
The principle is to call the window.print() metho...
How to modify the style of the el-select componen...
This article uses an example to illustrate how to...
Every website usually encounters many non-search ...