Fogo's answer 2020-09-07：
knock docker network ps command , Show three modes .
1.bridge Pattern ： Use –net =bridge Appoint , default setting . Bridge network mode ( Default ).
Default network mode for containers ,docker At installation time, a file named docker0 Of Linux bridge, Not specified –network Under the circumstances , All containers created will default to docker0 above .
2.host(open) Pattern ： Use –net =host Appoint . Open network mode , Share the network with the host .
Through the command –network=host Appoint , Use host The pattern container can be used directly docker host Of IP The address communicates with the outside world , The service port inside the container can also use the port of the host , There is no need for NAT,host The biggest advantage is that the network performance is better , however docker host The port already used on cannot be used anymore , The isolation of the network is not good .
3.none(close) Pattern ： Use –net =none Appoint . Closed network model , Do not configure networks for containers .
In this network mode, the container only has lo Loopback network , There are no other network cards .none The network can be created through --network=none To specify the . This type of network has no way to connect to the Internet , Closed network can guarantee the security of container .
4.container(join) Pattern ： Use –net =container:NAMEorID Appoint . Federated mount network mode , Share the network with other containers .
Create the container with –network=container:NAME_or_ID This pattern specifies when creating a new container that the network of the container shares with an existing container Network Namespace, But not for docker The container does any network configuration , This docker The container has no network card 、IP、 Routing information , It needs to be done manually docker Add network card to container 、 To configure IP etc. .
There are mainly three kinds of network drivers for user-defined mode ：bridge、overlay、macvlan.bridge The driver is used to create something similar to the one mentioned earlier bridge The Internet ;overlay and macvlan The driver is used to create a cross host network 、IP etc. .