forked from philipz/docker_practice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rewrite the introduction of advanced network chapter; redraw the figure
- Loading branch information
Showing
3 changed files
with
7 additions
and
4 deletions.
There are no files selected for viewing
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
#高级网络配置 | ||
当Docker启动时,会在主机上创建一个docker0的虚拟网卡。他随机挑选RFC1918私有网络中的一段地址给docker0。比如`172.17.42.1/16`,16位掩码的网段可以提供65534个地址供使用,这对主机和容器来说应该足够了。 | ||
本章将介绍Docker的一些高级网络配置和选项。 | ||
|
||
本章将介绍Docker的高级网络配置,一般情况下你不需要知道这些也可以使Docker正常工作。简单的网络配置和介绍请看第五章内容。 | ||
docker0 不是普通的网卡,他是桥接到其他网卡的虚拟网卡,容器使用它来和主机相互通信。当创建一个docker容器的时候,它就创建了一个对接口,当数据包发送到一个接口时,另外一个接口也可以收到相同的数据包,它们是绑在一起的一对孪生接口。这对接口在容器中那一端的的名字是eth0,宿主主机端的会指定一个唯一的名字,比如vethAQI2QT这样的名字,这种接口名字不再主机的命名空间中。所有的veth*的接口都会桥接到docker0,这样docker就创建了在主机和所有容器之间一个虚拟共享网络。 | ||
当Docker启动时,会自动在主机上创建一个`docker0`虚拟网桥,实际上是Linux的一个bridge,可以理解为一个软件交换机。它会在挂载到它的网口之间进行转发。 | ||
|
||
同时,Docker随机分配一个本地未占用的私有网段(在[RFC1918](http://tools.ietf.org/html/rfc1918)中定义)中的一个地址给`docker0`接口。比如典型的`172.17.42.1`,掩码为`255.255.0.0`。此后启动的容器内的网口也会自动分配一个同一网段(`172.17.0.0/16`)的地址。 | ||
|
||
 | ||
当创建一个Docker容器的时候,同时会创建了一对`veth pair`接口(当数据包发送到一个接口时,另外一个接口也可以收到相同的数据包)。这对接口一端在容器内,即`eth0`;另一端在本地并被挂载到`docker0`网桥,名称以`veth`开头(例如`vethAQI2QT`)。通过这种方式,主机可以跟容器通信,容器之间也可以相互通信。Docker就创建了在主机和所有容器之间一个虚拟共享网络。 | ||
|
||
|
||
 | ||
|
||
接下来的部分将介绍在一些场景中,docker所有的网络定制配置。linux的原生命令将调整、补充、甚至替换docker默认的网络配置。 |