Container interconnection between multiple physical hosts of Docker
The default bridge Nic of Docker is docker0. It only bridges all container NICs on the local machine. For example, the virtual Nic of the container is generally called veth * on the host, while Docker only bridges all these NICs, as shown below:
[Root @ opnvz ~] # Brctl show
Bridge name bridge id STP enabled interfaces
Docker0 8000.56847afe9799 no veth0889
Veth3c7b
The address seen in the container in veth4061 is generally like the following:
Root @ ac6474aeb31d :~ # Ip
1: lo: <LOOPBACK, UP, LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
Link/loopback 00: 00: 00: 00: 00: 00 brd 00: 00: 00: 00: 00: 00
Inet 127.0.0.1/8 scope host lo
Valid_lft forever preferred_lft forever
Inet6: 1/128 scope host
Valid_lft forever preferred_lft forever
11: eth0: <BROADCAST, UP, LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
Link/ether 4a: 7d: 68: da: 09: cf brd ff: ff
Inet 172.17.0.3/16 scope global eth0
Valid_lft forever preferred_lft forever
Inet6 fe80: 0000d: 68ff: feda: 9cf/64 scope link
Valid_lft forever preferred_lft forever this way, you can regard this network as a private network, connect to the Internet through nat, if you want to connect the Internet to the container, You Need To Do port ing, that is, the-p parameter.
If an application is applied within an enterprise or a cluster of multiple physical hosts, you may need to group containers of multiple physical hosts to one physical network, then we need to bridge the bridge to the network card we specified.
Topology
The NICS of host A and host B are connected to the same vlan 101 of the physical switch. In this way, the two NICs are equivalent to the same physical network, container 1, container 3, and container 4 are also in the same physical network. They can communicate with each other and communicate with other physical machines in the same vlan.
Physical Topology
Ubuntu example
The following uses ubuntu as an example to create container networking for multiple hosts: Create your own bridge and edit the/etc/network/interface file.
Auto br0
Iface br0 inet static
Address 192.168.7.31
Netmask 255.255.240.0
Gateway 192.168.7.254
Bridge_ports em1
Bridge_stp off
Dns-nameservers 8.8.8.8 192.168.6.1
Bind the default Bridge of Docker to the new br0, and then bind the container on this machine to the physical network corresponding to the em1 Nic.
Modify the/etc/default/docker file in ubuntu and add the last line of content.
# Docker Upstart and SysVinit configuration file
# Customize location of Docker binary (especially for development testing ).
# DOCKER = "/usr/local/bin/docker"
# Use DOCKER_OPTS to modify the daemon startup options.
# DOCKER_OPTS = "-- dns 8.8.8.8 -- dns 8.8.4.4"
# If you need Docker to use an HTTP proxy, it can also be specified here.
# Export http_proxy = "http: // FIG: 3128 /"
# This is also a handy place to tweak where Docker's temporary files go.
# Export TMPDIR = "/mnt/bigdrive/docker-tmp"
DOCKER_OPTS = "-B = br0"
Use the-B parameter when starting Docker to bind the container to the physical network. After restarting the Docker service, enter the container to see that it has been bound to your physical network.
Root @ ubuntudocker :~ # Docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
58b043aa05eb pai_hz: v1 "/startup. sh" 5 days ago Up 2 seconds 5900/tcp, 6080/tcp, 22/tcp yanlx
Root @ ubuntudocker :~ # Brctl show
Bridge name bridge id STP enabled interfaces
Br0 8000.7e6e617c8d53 no em1
Vethe6e5
In this way, containers are directly exposed to the physical network, and containers of multiple physical hosts can also be connected to the Internet. Note that you need to ensure the network security of the container by yourself.
For more Docker tutorials, see the following:
Docker installation application (CentOS 6.5_x64)
Configure Docker on Ubuntu 16.04 Server
Install Docker in Ubuntu 15.04
Docker installation instance
Create a basic image using Docker
How to install Docker on Ubuntu 15.04 and its basic usage
Docker usage notes on Ubuntu 16.04
Use Docker to start common applications in minutes
Solution for changing the configuration file of Docker in Ubuntu 16.04 does not take effect
Docker details: click here
Docker: click here
This article permanently updates link: https://www.bkjia.com/Linux/2018-02/151087.htm