Docker offers several primary network, from the coverage of the network can be divided on a single host vessel and across multiple host network.
Doker automatically creates three networks on the host at the time of installation, use the following command to view
docker network ls
none Network
Named Incredibles, none network is nothing networks. It hung in the container in addition to this network lo, no other cards. When the container is created, you can use none --network = none specified network.
The network typically applied to some applications and does not require high security requirements of the network, such as a container only purpose is to generate a random password, the network can put none avoid password hacking
host network
The container connected to the host network share Docker host network stack, the network configuration and the container exactly the same host. --Network = host can be specified using the host network.
In containers you can see all the host of the network card, and even the hostname is the host. Host network usage scenario is as follows:
Directly Docker host the biggest advantage is that network performance, if the container has higher requirements for network transmission efficiency, you can select the host network. Of course, the inconvenience is to sacrifice some flexibility, for example, to consider the port conflict, the Docker host port already in use can not be used again.
Another use of Docker host is configured so that containers can directly host network. For example, some of the cross-host network solution, which itself is in a container run these programs need to configure the network, such as management iptables.
brige network operations
brige network is the most widely used type of network.
Creates a named linux bridge docker0 when Docker installation. If you do not specify --network, create a default container will be linked to the docker0.
brctl show
Docker0 currently not on any other network device
Create a network called net1's Bridge
docker network create net1
View net bridge, subnet has been configured to automatically
docker network inspect net1
Create a file called net2 the bridge bridge, designated subnet = 172.10.10.0 / 24
docker network create --driver bridage --subnet 172.10.10.0/24 --gateway 172.10.10.1 net2
Start container named centos1 and join the network net1
docker run --name centos1 -dit --network=net1 centos
Start centos2 named container, and added net2 network
boot centos3 the container named, net2 and join the network, while the vessel designated IP = 172.10.10.10docker run --name centos3 -dit --network=net2 --ip 172.10.10.10 centos
View centos were three containers of IP address information. And wherein cnetos2 centos3 the same network segment, with the former two centos1 located on different network segmentsdocker inspect centos1
docker inspect centos2
docker inspect centos3
In FIG understood below this bridge network
vessel is connected through the main to brigde veth pair network, which is a special network devices in pairs, simple stack of cards will be appreciated by a line connecting the virtual network, network card a (e.g. eth @ if34) in a container, an additional (e.g. veth28c57df) hanging on the bridge docker0