Docker Detailed Explanation (14) - Detailed Explanation of Docker Network Types

Today, I will continue to introduce the relevant knowledge of Linux operation and maintenance. The main content of this article is a detailed explanation of Docker network types.

1. Docker network type

In Docker, there are four modes of container network, namely None, Bridge, Container and Host. Below, I will explain these four types of network modes in detail.

2. None type network

None type of network, that is, no network, the Docker container will not set any information about the network in the container, and will not configure any network, but we can add configuration to the container and give it a network environment.
We sometimes need to assign a static IP to the container network, so that the Docker container is on the same network segment as the physical machine. At this time, we can use the None type of network first, and then choose the network information ourselves.
When creating a Docker container, we can use --net=none to specify that the Docker container is in a network of type None.

3. Bridge type network

Bridge type network is the default network type of Docker container. In this mode, Docker will virtualize a network for the container. All Container containers will be assigned an IP address in this network, and different Containers can communicate with each other.
The Brdige virtual network of the Docker container is as follows:
insert image description here
The network topology in Bridge mode is as follows:
insert image description here
**As can be seen from the above figure, Docker's "Bridge" and Vmware's "Bridge" are not the same type of network at all! **Actually, "Bridge" in Docker is more similar to Nat-type networking mode in Vmware. Moreover, the access of the Docker container to the external network (Internet) is also realized based on the Nat mechanism of the physical machine. When creating a Docker container, we can use --net=bridge to specify that the Docker container is in a Bridge-type network. Note: Bridge is the default network type of Docker, so even if we don't use the --net=bridge parameter, the network type of the Docker container is still Brdige

4. Container type network

In a Container-type network, multiple Docker containers share network devices. After a Docker container is running, when we run other Docker containers, we can make the container share the network with the previously running Docker container, that is, have the same IP address and network card device. The two containers can communicate through the loopback address network card, and achieve isolation in terms of file system, process table, etc. For containers in the same Container network, the port occupation mechanism is first-come-first-occupancy mode, whichever container occupies the port can use the port.
When creating a Docker container, we can use --net=container to specify that the Docker container is in a Container-type network.

5. Host type network

Similar to the Container type network, in the Host type network, the Docker container shares the network with the physical machine and has the IP address and network card information of the physical machine. Similarly, in the Host-type network mode, the Docker container is isolated from the physical machine in terms of file system, process, etc. For example, if a Docker container with Web80 port service enabled is in a Host-type network (provided that the physical machine does not occupy port 80 first), then accessing the container only needs to access the IP address of the physical machine.
When creating a Docker container, we can use --net=host to specify that the Docker container is in a network of type Host.
Originality is not easy, please indicate the source for reprinting: https://blog.csdn.net/weixin_40228200

Guess you like

Origin blog.csdn.net/weixin_40228200/article/details/124224875
Recommended