非常教程

Docker 17参考手册

引擎 | Engine

开始使用macvlan网络驱动程序 | Get started with macvlan network driver (Engine)

Libnetwork 使用户可以完全控制 IPv4 和I Pv6 寻址。VLAN 驱动程序建立在此基础之上,为运营商提供对感兴趣进行底层网络集成的用户的二层 VLAN 标记的完全控制。对于抽象掉物理约束的重叠部署,请参阅多主机重叠驱动程序。

Macvlan 是经过验证的真正网络虚拟化技术的新转折点。Linux实施非常轻便,因为它们不是使用传统的 Linux桥接进行隔离,而是与 Linux 以太网接口或子接口关联,以实现网络间的分离和与物理网络的连接。

Macvlan 提供了许多独特的功能,并为各种模式的进一步创新提供了充足的空间。这些方法的两个高级优势是,绕过 Linux 桥接的积极性能影响以及移动部件少的简单性。移除 Docker 主机 NIC 和容器接口之间传统上的桥接会留下一个非常简单的设置,由容器接口组成,直接连接到 Docker 主机接口。由于在这些场景中没有端口映射,因此该结果易于访问面向外部的服务。

Pre-Requisites

  • 这个页面上的例子都是使用 Docker 1.12.0+的单个主机和设置
  • 所有示例都可以在运行 Docker 的单个主机上执行。任何使用子接口的例子eth0.10都可以替换eth0为 Docker 主机上的任何其他有效的父接口。动态.创建子接口。-o parent接口也可以docker network create全部排除在外,驱动程序将创建一个dummy接口,使本地主机连接性能够执行示例。
  • 内核要求:
- To check your current kernel version, use `uname -r` to display your kernel version
- Macvlan Linux kernel v3.9–3.19 and 4.0+

Macvlan Bridge 模式示例用法

Macvlan Bridge 模式每个容器都有一个唯一的 MAC 地址,用于跟踪 Docker 主机的 MAC 映射到端口映射。

  • Macvlan 驱动程序网络连接到父 Docker主机接口。例如物理接口,如eth0用于 802.1q VLAN标记的子接口eth0.10.10代表VLAN 10),甚至包含将两个以太网接口捆绑为单个逻辑接口的捆绑主机适配器。
  • 指定的网关在网络基础结构提供的主机外部。
  • 每个 Macvlan Bridge 模式 Docker 网络彼此隔离,一次只能有一个网络连接到父接口。Docker网络可以连接的每个主机适配器有4,094个子接口的理论限制。
  • 同一子网内的任何容器都可以在没有网关的情况下与同一网络中的任何其他容器通话macvlan bridge
  • 相同的docker network命令适用于vlan驱动程序。
  • 在 Macvlan 模式下,不通过两个网络/子网之间的外部流程路由,单独网络上的容器无法到达彼此。这也适用于同一个码头网络中的多个子网。

在以下示例中,eth0泊坞窗主机在172.16.86.0/24网络上有一个IP,并且有一个默认网关172.16.86.1。网关是一个地址为的外部路由器172.16.86.1eth0bridge模式下,Docker 主机接口上不需要IP地址,只需将其置于正确的上游网络中即可通过网络交换机或网络路由器转发。

注意:对于 Macvlan 桥接模式,子网值需要与 Docker 主机的 NIC 接口相匹配。例如,使用该-o parent=选项指定的 Docker 主机以太网接口的相同子网和网关。

  • 此示例中使用的父接口是eth0并且位于子网上172.16.86.0/24docker network意志中的容器也需要与父代在同一个子网上-o parent=。网关是网络上的外部路由器,不是任何ip伪装或任何其他本地代理。
  • 驱动程序是用-d driver_name选项指定的。在这种情况下-d macvlan
  • 父接口-o parent=eth0配置如下:
ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet 172.16.86.250/24 brd 172.16.86.255 scope global eth0

创建 macvlan 网络并运行连接到它的几个容器:

# Macvlan  (-o macvlan_mode= Defaults to Bridge mode if not specified)
docker network create -d macvlan \
    --subnet=172.16.86.0/24 \
    --gateway=172.16.86.1  \
    -o parent=eth0 pub_net

# Run a container on the new network specifying the --ip address.
docker  run --net=pub_net --ip=172.16.86.10 -itd alpine /bin/sh

# Start a second container and ping the first
docker  run --net=pub_net -it --rm alpine /bin/sh
ping -c 4 172.16.86.10

看看容器IP和路由表:

ip a show eth0
    eth0@if3: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UNKNOWN
    link/ether 46:b2:6b:26:2f:69 brd ff:ff:ff:ff:ff:ff
    inet 172.16.86.2/24 scope global eth0

ip route
    default via 172.16.86.1 dev eth0
    172.16.86.0/24 dev eth0  src 172.16.86.2

# NOTE: the containers can NOT ping the underlying host interfaces as
# they are intentionally filtered by Linux for additional isolation.
# In this case the containers cannot ping the -o parent=172.16.86.250

您可以明确指定bridge模式选项-o macvlan_mode=bridge。这是默认设置,因此将以bridge任何一种方式进行。

虽然eth0接口不需要在 Macvlan Bridge 中拥有 IP 地址,但在接口上使用 IP 地址并不罕见。通过使用该--aux-address=x.x.x.x标志,可以将地址从默认的内置 IPAM 中获取地址。这会将指定的地址黑名单分发给容器。上面的同一网络示例阻止将-o parent=eth0地址分发到容器。

docker network create -d macvlan \
    --subnet=172.16.86.0/24 \
    --gateway=172.16.86.1  \
    --aux-address="exclude_host=172.16.86.250" \
    -o parent=eth0 pub_net

在由默认的 Docker IPAM 驱动程序提供的网络中选择子池IP地址的另一个选项是使用--ip-range=。这将指定驱动程序从此池中分配容器地址,而不是--subnet=从网络创建的参数中分配更广泛的范围,如以下示例中所示,该示例将分配192.168.32.128从此处开始并向上递增的地址。

docker network create -d macvlan  \
    --subnet=192.168.32.0/24  \
    --ip-range=192.168.32.128/25 \
    --gateway=192.168.32.254  \
    -o parent=eth0 macnet32

# Start a container and verify the address is 192.168.32.128
docker run --net=macnet32 -it --rm alpine /bin/sh

网络可以通过以下方式删除:

docker network rm <network_name or id>

注意:在 Macvlan 中,您无法使用默认名称空间IP地址进行 ping 或通信。例如,如果您创建一个容器,并尝试 ping 多克尔主机eth0无法正常工作。该流量被内核模块明确过滤以提供额外的提供者隔离和安全性。

有关 Docker 网络命令的更多信息,请参阅使用 Docker 网络命令

Macvlan 802.1q中继桥接模式示例用法

VLAN(虚拟局域网)长期以来一直是虚拟化数据中心网络的主要手段,并且现在仍然在几乎所有现有网络中。VLAN 通过标记第2层隔离域,并使用从1-4094范围内插入到包头中的12位标识符来实现,该包头允许对 IPv4 和 IPv6 的单个或多个子网进行逻辑分组。这是很常见的网络运营商使用基于子网(或多个)功能或安全简档,如 VLAN 分隔交通webdb或任何其它隔离的需要。

计算主机要求在主机上同时运行多个虚拟网络是非常普遍的。长期以来,Linux 网络支持 VLAN 标记(也称为802.1q),用于维护网络之间的数据通路隔离。连接到 Docker 主机的以太网链路可以配置为支持802.1q VLAN ID,方法是创建 Linux 子接口,每个子接口专用于一个唯一的 VLAN ID。

将 802.1q 中继到 Linux 主机对于许多操作来说非常痛苦。它需要更改配置文件才能在重新启动后保持不变。如果涉及网桥,则需要将物理网卡移入网桥,然后网桥获取IP地址。这导致了许多搁浅的服务器,因为在该复杂过程中切断访问的风险很高。

像所有的 Docker 网络驱动程序一样,总体目标是减轻管理网络资源的操作痛苦。为此,当网络接收到不存在的父接口的子接口时,驱动程序会在创建网络时创建带 VLAN 标记的接口。

在主机重启的情况下,当 Docker 守护进程重新启动时,驱动程序将重新创建所有网络链接,而不需要修改经常复杂的网络配置文件。驱动程序会跟踪它是否创建了最初使用网络创建的 VLAN 标记的子接口,并且只会在重新启动后重新创建子接口,或者docker network rm如果首先使用链接创建链接,则会删除该链接docker network create

如果用户不想让 Docker 修改-o parent子接口,用户只需要传递一个已经存在的现有链接作为父接口。父接口eth0不会被删除,只有不是主链接的子接口。

驱动程序需要添加/删除 vlan子接口interface_name.vlan_tag

例如:eth0.50表示与vlan id标记eth0的从站的父接口。等效的命令是。eth0.5050ip linkip link add link eth0 name eth0.50 type vlan id 50

Vlan ID 50

在由 Docker 主机标记和隔离的第一个网络中,eth0.50父节点是使用50指定的 vlan id 标记的-o parent=eth0.50。可以使用其他命名格式,但需要使用ip link或 Linux 配置文件手动添加和删除链接。只要-o parent存在任何可以使用的东西,只要符合 Linux netlink。

# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged
docker network  create  -d macvlan \
    --subnet=192.168.50.0/24 \
    --gateway=192.168.50.1 \
    -o parent=eth0.50 macvlan50

# In two separate terminals, start a Docker container and the containers can now ping one another.
docker run --net=macvlan50 -it --name macvlan_test5 --rm alpine /bin/sh
docker run --net=macvlan50 -it --name macvlan_test6 --rm alpine /bin/sh

Vlan ID 60

在第二个网络中,由 Docker 主机进行标记和隔离,eth0.60是使用60指定的vlan id标记的父接口-o parent=eth0.60。该macvlan_mode=默认macvlan_mode=bridge。它也可以显式设置,结果与下一个示例中显示的结果相同。

# now add networks and hosts as you would normally by attaching to the master (sub)interface that is tagged.
docker network  create  -d macvlan \
    --subnet=192.168.60.0/24 \
    --gateway=192.168.60.1 \
    -o parent=eth0.60 \
    -o macvlan_mode=bridge macvlan60

# In two separate terminals, start a Docker container and the containers can now ping one another.
docker run --net=macvlan60 -it --name macvlan_test7 --rm alpine /bin/sh
docker run --net=macvlan60 -it --name macvlan_test8 --rm alpine /bin/sh

Example: Multi-Subnet Macvlan 802.1q Trunking

与之前的示例相同,除了绑定到网络的附加子网用户可以选择放置容器。在MacVlan / Bridge模式下,除非在两个子网之间有路由流量的外部路由器(回答ARP等),否则容器只能在相同的子网/广播域上互相ping通。

### Create multiple L2 subnets
docker network create -d ipvlan \
    --subnet=192.168.210.0/24 \
    --subnet=192.168.212.0/24 \
    --gateway=192.168.210.254  \
    --gateway=192.168.212.254  \
     -o ipvlan_mode=l2 ipvlan210

# Test 192.168.210.0/24 connectivity between containers
docker run --net=ipvlan210 --ip=192.168.210.10 -itd alpine /bin/sh
docker run --net=ipvlan210 --ip=192.168.210.9 -it --rm alpine ping -c 2 192.168.210.10

# Test 192.168.212.0/24 connectivity between containers
docker run --net=ipvlan210 --ip=192.168.212.10 -itd alpine /bin/sh
docker run --net=ipvlan210 --ip=192.168.212.9 -it --rm alpine ping -c 2 192.168.212.10

双栈IPv4 IPv6 Macvlan桥接模式

例如: Macvlan Bridge模式,802.1q中继,VLAN ID:218,多子网,双协议栈

# Create multiple bridge subnets with a gateway of x.x.x.1:
docker network  create  -d macvlan \
    --subnet=192.168.216.0/24 --subnet=192.168.218.0/24 \
    --gateway=192.168.216.1  --gateway=192.168.218.1 \
    --subnet=2001:db8:abc8::/64 --gateway=2001:db8:abc8::10 \
     -o parent=eth0.218 \
     -o macvlan_mode=bridge macvlan216

# Start a container on the first subnet 192.168.216.0/24
docker run --net=macvlan216 --name=macnet216_test --ip=192.168.216.10 -itd alpine /bin/sh

# Start a container on the second subnet 192.168.218.0/24
docker run --net=macvlan216 --name=macnet216_test --ip=192.168.218.10 -itd alpine /bin/sh

# Ping the first container started on the 192.168.216.0/24 subnet
docker run --net=macvlan216 --ip=192.168.216.11 -it --rm alpine /bin/sh
ping 192.168.216.10

# Ping the first container started on the 192.168.218.0/24 subnet
docker run --net=macvlan216 --ip=192.168.218.11 -it --rm alpine /bin/sh
ping 192.168.218.10

查看其中一个容器的详细信息:

docker run --net=macvlan216 --ip=192.168.216.11 -it --rm alpine /bin/sh

root@526f3060d759:/# ip a show eth0
    eth0@if92: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default
    link/ether 8e:9a:99:25:b6:16 brd ff:ff:ff:ff:ff:ff
    inet 192.168.216.11/24 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 2001:db8:abc4::8c9a:99ff:fe25:b616/64 scope link tentative
       valid_lft forever preferred_lft forever
    inet6 2001:db8:abc8::2/64 scope link nodad
       valid_lft forever preferred_lft forever

# Specified v4 gateway of 192.168.216.1
root@526f3060d759:/# ip route
  default via 192.168.216.1 dev eth0
  192.168.216.0/24 dev eth0  proto kernel  scope link  src 192.168.216.11

# Specified v6 gateway of 2001:db8:abc8::10
root@526f3060d759:/# ip -6 route
  2001:db8:abc4::/64 dev eth0  proto kernel  metric 256
  2001:db8:abc8::/64 dev eth0  proto kernel  metric 256
  default via 2001:db8:abc8::10 dev eth0  metric 1024

实施例,使用,网络,搬运工,文档,用户指南,macvlan,群集

引擎 | Engine相关

1..NET核心应用程序(引擎) | .NET Core application (Engine)
2.关于图像,容器和存储驱动程序(引擎) | About images, containers, and storage drivers (Engine)
3.向swarm添加节点(Engine) | Add nodes to the swarm (Engine)
4.应用自定义元数据(引擎) | Apply custom metadata (Engine)
5.应用滚动更新(引擎) | Apply rolling updates (Engine)
6.apt-cacher-ng
7.编写Dockerfiles(引擎)的最佳实践 | Best practices for writing Dockerfiles (Engine)
8.二进制(引擎) | Binaries (Engine)
9.将容器端口绑定到主机(引擎) | Bind container ports to the host (Engine)
10.突破性变化(引擎) | Breaking changes (Engine)
11.建立自己的网桥 | Build your own bridge (Engine)
12.CentOS (Engine)
13.CentOS (Engine)
14.配置容器DNS(引擎) | Configure container DNS (Engine)
15.在用户定义的网络中配置容器DNS(引擎) | Configure container DNS in user-defined networks (Engine)
16.CouchDB (Engine)
17.创建基本映像(引擎) | Create a base image (Engine)
18.创建群(引擎) | Create a swarm (Engine)
19.自定义docker0网桥(引擎) | Customize the docker0 bridge (Engine)
20.Debian (Engine)
21.默认桥接网络 | Default bridge network
22.删除服务(引擎) | Delete the service (Engine)
23.部署服务(引擎) | Deploy a service (Engine)
24.将服务部署到一个群(引擎) | Deploy services to a swarm (Engine)
25.不推荐的引擎功能 | Deprecated Engine features
26.Docker容器网络(引擎) | Docker container networking (Engine)
27.Docker概述(引擎) | Docker overview (Engine)
28.Docker运行参考(引擎) | Docker run reference (Engine)
29.Dockerfile引用(引擎) | Dockerfile reference (Engine)
30.Dockerize应用程序 | Dockerize an application
31.排空节点(引擎) | Drain a node (Engine)
32.引擎 | Engine
33.FAQ(引擎) | FAQ (Engine)
34.Fedora (Engine)
35.开始 | Get started (Engine)
36.开始使用多主机网络 | Get started with multi-host networking (Engine)
37.节点如何工作 | How nodes work (Engine)
38.服务如何运作(引擎) | How services work (Engine)
39.图像管理 | Image management (Engine)
40.检查服务(引擎) | Inspect the service (Engine)
41.安装Docker(引擎) | Install Docker (Engine)
42.IPv6与Docker(引擎) | IPv6 with Docker (Engine)
43.将节点加入群集(引擎) | Join nodes to a swarm (Engine)
44.旧容器链接(引擎) | Legacy container links (Engine)
45.锁定你的群(引擎) | Lock your swarm (Engine)
46.管理群中的节点(引擎) | Manage nodes in a swarm (Engine)
47.使用Docker机密管理敏感数据(引擎) | Manage sensitive data with Docker secrets (Engine)
48.使用PKI管理swarm安全性(引擎) | Manage swarm security with PKI (Engine)
49.管理群体服务网络(引擎) | Manage swarm service networks (Engine)
50.迁移到引擎1.10 | Migrate to Engine 1.10
51.可选的Linux安装后步骤(引擎) | Optional Linux post-installation steps (Engine)
52.总览 | Overview (Engine)
53.总览 | Overview (Engine)
54.PostgreSQL(引擎) | PostgreSQL (Engine)
55.群集模式中的筏共识(引擎) | Raft consensus in swarm mode (Engine)
56.Riak (Engine)
57.以群集模式运行Docker Engine | Run Docker Engine in swarm mode
58.扩展服务(引擎) | Scale the service (Engine)
59.SDKs (Engine)
60.选择一个存储驱动 | Select a storage driver (Engine)
61.设置教程(引擎) | Set up for the tutorial (Engine)
62.SSHd (Engine)
63.存储驱动总览 | Storage driver overview (Engine)
64.存储服务配置数据(引擎) | Store service configuration data (Engine)
65.Swarm管理指南(引擎) | Swarm administration guide (Engine)
66.Swarm模式关键概念(引擎) | Swarm mode key concepts (Engine)
67.Swarm模式覆盖网络安全模型(引擎) | Swarm mode overlay network security model (Engine)
68.群模式概述(引擎) | Swarm mode overview (Engine)
69.Ubuntu (Engine)
70.Ubuntu (Engine)
71.了解容器通信(引擎) | Understand container communication (Engine)
72.使用多阶段构建(引擎) | Use multi-stage builds (Engine)
73.使用swarm模式路由网格(引擎) | Use swarm mode routing mesh (Engine)
74.使用AUFS存储驱动程序(引擎) | Use the AUFS storage driver (Engine)
75.使用Btrfs存储驱动程序(引擎) | Use the Btrfs storage driver (Engine)
76.使用设备映射器存储驱动程序(引擎) | Use the Device mapper storage driver (Engine)
77.使用OverlayFS存储驱动程序(引擎) | Use the OverlayFS storage driver (Engine)
78.使用VFS存储驱动程序(引擎) | Use the VFS storage driver (Engine)
79.使用ZFS存储驱动程序(引擎) | Use the ZFS storage driver (Engine)
80.处理图像 | Work with images
81.使用网络命令(引擎) | Work with network commands (Engine)
Docker 17

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

主页 https://docker.com/
源码 https://github.com/docker/docker
版本 17
发布版本 17.06