Get the App
SLTechnology News&Howtos  ›  Servers  › 

A brief introduction to the Network Mode of Docker

Shulou Source: shulou.com Published: 2022-06-02 09:49:03 09月29日 Update

When creating a docker container, there are four network modes to choose from

Bridge mode (default mode)

Host mode

Container mode

None mode

Bridge mode is the default network mode of docker. If you don't write the-net parameter, it is bridge mode.

When the Docker process starts, a virtual bridge named docker0 is created on the host, and the Docker container launched on this host is connected to the virtual bridge.

The ip of the docker0 bridge is 172.17.0.1 IP 24. The bridge assigns a separate IP to each container (at 172.17.0.0) and sets the IP address of the docker0 as the default gateway for the container.

Create a pair of virtual network card veth pair devices on the host, and Docker will place one end of the veth pair device in the newly created container and name it eth0 (the container's network card), and the other end in the docker0 bridge, named after a similar name such as vethxxx.

That is, in bridge mode, each container has a separate network and namespace.

Brctl show

The Container mode specifies that a newly created container and an existing container share a Network Namespace and network information, while others, such as file systems, process lists, and so on, are isolated.

In other words, the two containers share an IP (eth0) information, where the two containers are equivalent to one container in the bridge mode, and the processes of the two containers can communicate through the lo Nic device.

As with bridge mode, the network and namespaces of containers and hosts are still isolated.

In Host mode, the container and host share the Nic information and namespace, and the container does not have a separate IP. However, other aspects of the container, such as file systems, process lists, and so on, are isolated from the host.

Using none mode, the Docker container has its own Network Namespace, but there is no network configuration for the Docker container. In other words, the Docker container does not have network card, IP, routing and other information. We need to add network cards, configure IP and so on for the Docker container.

Tags: Container mode network network card bridge information process two host space device independent isolated one end name file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB macOS MySQL Docker vpn