非常教程

Docker 17参考手册

引擎 | Engine

以群集模式运行Docker Engine | Run Docker Engine in swarm mode

当您首次安装并开始使用Docker Engine时,群集模式默认处于禁用状态。当您启用群集模式时,您将使用通过docker service命令管理的服务概念。

在群集模式下运行引擎有两种方法:

  • 创建一个新的群体,在本文中讨论。
  • 加入现有的群。

当您在本地计算机上以群集模式运行引擎时,可以根据您创建的映像或其他可用映像来创建和测试服务。在您的生产环境中,群集模式提供具有群集管理功能的容错平台,以保持您的服务正常运行。

这些说明假定您已经在机器上安装了Docker Engine 1.12或更高版本,以充当群中的管理器节点。

如果还没有,请阅读群模式关键概念并尝试群模式教程。

形成一群

当您运行命令创建群集时,Docker引擎开始以群集模式运行。

运行docker swarm init以在当前节点上创建单节点群。引擎设置如下:

  • 将当前节点切换为群集模式。
  • 创建一个名为的default群。
  • 指定当前节点为群集的领导管理节点。
  • 用机器主机名命名节点。
  • 将管理器配置为侦听端口2377上的活动网络接口。
  • 将当前节点设置为Active可用性,这意味着它可以从调度程序接收任务。
  • 为参与群体的引擎启动一个内部分布式数据存储,以维护群集及其上运行的所有服务的一致视图。
  • 默认情况下,为该群体生成一个自签名的根CA.
  • 默认情况下,为worker和manager节点生成令牌以加入群集。
  • 创建一个覆盖网络ingress,该网络命名为发布群体外部的服务端口。

输出用于docker swarm init提供在将新工作节点加入群集时使用的连接命令:

$ docker swarm init
Swarm initialized: current node (dxn1zf6l61qsb1josjja83ngz) is now a manager.

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.99.100:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

配置广告地址

管理器节点使用通告地址允许群中的其他节点访问Swarmkit API并覆盖网络。群中的其他节点必须能够通过其通告地址IP地址访问管理器节点。

如果您未指定广告地址,则Docker将检查系统是否具有单个IP地址。如果是这样,默认情况下,Docker使用侦听端口的IP地址2377。如果系统有多个IP地址,则必须指定正确的--advertise-addr以启用管理员间通信和覆盖网络:

$ docker swarm init --advertise-addr <MANAGER-IP>

您还必须指定--advertise-addr其他节点到达第一个管理器节点的地址是否与管理员认为的地址不同。例如,在跨越不同区域的云设置中,主机具有用于在该区域内访问的内部地址和用于从该区域外访问的外部地址。在这种情况下,请指定外部地址,--advertise-addr以便节点可以将该信息传播到随后连接到其上的其他节点。

docker swarm init有关广告地址的更多详细信息,请参阅CLI参考。

查看加入命令或更新群集连接令牌

节点需要一个秘密的令牌来加入群。工作节点的标记与管理器节点的标记不同。节点在加入群时只使用连接令牌。在节点已经加入群体之后旋转连接令牌不会影响节点的群集成员资格。令牌轮转可确保任何尝试加入群集的新节点都不能使用旧令牌。

要检索包含工作节点的连接令牌的连接命令,请运行:

$ docker swarm join-token worker

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c \
    192.168.99.100:2377

This node joined a swarm as a worker.

要查看管理器节点的连接命令和令牌,请运行:

$ docker swarm join-token manager

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-59egwe8qangbzbqb3ryawxzk3jn97ifahlsrw01yar60pmkr90-bdjfnkcflhooyafetgjod97sz \
    192.168.99.100:2377

通过--quiet标志只打印令牌:

$ docker swarm join-token --quiet worker

SWMTKN-1-49nj1cmql0jkz5s954yi3oex3nedyz0fb0xx14ie39trti4wxv-8vxv8rssmk743ojnwacrr2e7c

加入令牌时要小心,因为它们是加入群集所必需的秘密。特别是,将一个秘密检查到版本控制是一个不好的做法,因为它允许任何有权访问应用程序源代码的人向群中添加新节点。经理令牌特别敏感,因为它们允许新的经理节点加入并获得整个群体的控制权。

建议在以下情况下旋转联接令牌:

  • 如果令牌意外签入到版本控制系统,则组聊天或意外地打印到您的日志中。
  • 如果您怀疑某个节点已被破坏。
  • 如果您希望保证没有新的节点能够加入群集。

此外,对包括群集加入令牌在内的任何秘密实施定期轮换计划是最佳做法。我们建议您至少每6个月旋转一次令牌。

运行swarm join-token --rotate以使旧的令牌失效并生成新的令牌。指定是否要旋转workermanager节点的标记:

$ docker swarm join-token  --rotate worker

To add a worker to this swarm, run the following command:

    docker swarm join \
    --token SWMTKN-1-2kscvs0zuymrsc9t0ocyy1rdns9dhaodvpl639j2bqx55uptag-ebmn5u927reawo27s3azntd44 \
    192.168.99.100:2377

了解更多

  • 将节点连接到一个群中
  • swarm init命令行引用
  • 群模式教程

指导,群体模式,节点

引擎 | 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.开始使用macvlan网络驱动程序 | Get started with macvlan network driver (Engine)
37.开始使用多主机网络 | Get started with multi-host networking (Engine)
38.节点如何工作 | How nodes work (Engine)
39.服务如何运作(引擎) | How services work (Engine)
40.图像管理 | Image management (Engine)
41.检查服务(引擎) | Inspect the service (Engine)
42.安装Docker(引擎) | Install Docker (Engine)
43.IPv6与Docker(引擎) | IPv6 with Docker (Engine)
44.将节点加入群集(引擎) | Join nodes to a swarm (Engine)
45.旧容器链接(引擎) | Legacy container links (Engine)
46.锁定你的群(引擎) | Lock your swarm (Engine)
47.管理群中的节点(引擎) | Manage nodes in a swarm (Engine)
48.使用Docker机密管理敏感数据(引擎) | Manage sensitive data with Docker secrets (Engine)
49.使用PKI管理swarm安全性(引擎) | Manage swarm security with PKI (Engine)
50.管理群体服务网络(引擎) | Manage swarm service networks (Engine)
51.迁移到引擎1.10 | Migrate to Engine 1.10
52.可选的Linux安装后步骤(引擎) | Optional Linux post-installation steps (Engine)
53.总览 | Overview (Engine)
54.总览 | Overview (Engine)
55.PostgreSQL(引擎) | PostgreSQL (Engine)
56.群集模式中的筏共识(引擎) | Raft consensus in swarm mode (Engine)
57.Riak (Engine)
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