非常教程

Docker 17参考手册

引擎 | Engine

管理群中的节点(引擎) | Manage nodes in a swarm (Engine)

作为群体管理生命周期的一部分,您可能需要查看或更新节点,如下所示:

  • 列出群中的节点
  • 检查单个节点
  • 更新节点
  • 离开群

列出节点

要从docker node ls管理器节点查看群集中的节点列表,请执行以下操作:

$ docker node ls

ID                           HOSTNAME  STATUS  AVAILABILITY  MANAGER STATUS
46aqrk4e473hjbt745z53cr3t    node-5    Ready   Active        Reachable
61pi3d91s0w3b90ijw3deeb2q    node-4    Ready   Active        Reachable
a5b2m3oghd48m8eu391pefq5u    node-3    Ready   Active
e7p8btxeu3ioshyuj6lxiv6g0    node-2    Ready   Active
ehkv3bcimagdese79dn78otj5 *  node-1    Ready   Active        Leader

AVAILABILITY列显示调度程序是否可以将任务分配给节点:

  • Active 意味着调度程序可以将任务分配给节点。
  • Pause 意味着调度程序不会将新任务分配给节点,但现有任务仍在运行。
  • Drain意味着调度程序不会将新任务分配给节点。调度程序关闭所有现有任务并在可用节点上调度它们。

MANAGER STATUS列显示节点参与 Raft 共识:

  • 没有值表示不参与群管理的工作节点。
  • Leader 意味着节点是为群体进行所有群集管理和编排决策的主要管理者节点。
  • Reachable意味着该节点是参与Raft共识法定人数的经理节点。如果领导者节点变得不可用,该节点有资格被选为新领导者。
  • Unavailable意味着节点是无法与其他经理沟通的经理。如果管理器节点变得不可用,则应该将新管理器节点加入到群集中,或者将工作器节点提升为管理器。

有关群体管理的更多信息,请参阅群体管理指南。

检查单个节点

您可以docker node inspect <NODE-ID>在管理器节点上运行以查看单个节点的详细信息。输出默认为JSON格式,但您可以传递该--pretty标记以便以可读格式打印结果。例如:

$ docker node inspect self --pretty

ID:                     ehkv3bcimagdese79dn78otj5
Hostname:               node-1
Joined at:              2016-06-16 22:52:44.9910662 +0000 utc
Status:
 State:                 Ready
 Availability:          Active
Manager Status:
 Address:               172.17.0.2:2377
 Raft Status:           Reachable
 Leader:                Yes
Platform:
 Operating System:      linux
 Architecture:          x86_64
Resources:
 CPUs:                  2
 Memory:                1.954 GiB
Plugins:
  Network:              overlay, host, bridge, overlay, null
  Volume:               local
Engine Version:         1.12.0-dev

更新节点

您可以修改节点属性,如下所示:

  • 更改节点可用性
  • 添加或删除标签元数据
  • 更改节点角色

更改节点可用性

更改节点可用性可让您:

  • 耗尽管理器节点,以便仅执行群集管理任务并且不可用于任务分配。
  • 排空一个节点,这样你就可以把它拿下来进行维护。
  • 暂停节点,使其无法接收新任务。
  • 恢复不可用或暂停的节点可用状态。

例如,要将管理器节点更改为Drain可用性:

$ docker node update --availability drain node-1

node-1

有关不同可用性选项的说明,请参阅列表节点。

添加或删除标签元数据

节点标签提供了一种灵活的节点组织方法。您也可以在服务约束中使用节点标签。创建服务时应用约束以限制调度程序为服务分配任务的节点。

docker node update --label-add在管理器节点上运行以将标签元数据添加到节点。该--label-add标志支持<key><key>=<value>对或一对。

--label-add为要添加的每个节点标签传递一次标志:

$ docker node update --label-add foo --label-add bar=baz node-1

node-1

使用码头节点更新为节点设置的标签仅适用于群内的节点实体。不要将它们与 dockerd 的 docker 守护进程标签混淆。

因此,可以使用节点标签将关键任务限制为满足特定要求的节点。例如,仅在需要运行特殊工作负载的机器上进行调度,例如符合 PCI-SS合规性的机器。

受影响的工作人员无法损害这些特殊工作负载,因为它无法更改节点标签。

然而,引擎标签仍然很有用,因为一些不影响集装箱安全协调的功能可能更好地以分散方式设置。例如,引擎可以有一个标签来表明它具有某种类型的磁盘设备,这可能与安全性无关。这些标签更容易被 swarm 协调器“信任”。

docker service create有关服务约束的更多信息,请参阅 CLI参考。

升级或降级节点

您可以将工作者节点提升为经理角色。当管理器节点变得不可用或者您想让管理器脱机进行维护时,这非常有用。同样,您可以将经理节点降级为辅助角色。

注意:维护法定数量无论您提升或降级节点的理由如何,您都必须始终维护群体中的法定管理器节点。有关更多信息,请参阅 Swarm 管理指南。

要提升节点或一组节点,请docker node promote从管理器节点运行:

$ docker node promote node-3 node-2

Node node-3 promoted to a manager in the swarm.
Node node-2 promoted to a manager in the swarm.

要降级一个节点或一组节点,请docker node demote从管理器节点运行:

$ docker node demote node-3 node-2

Manager node-3 demoted in the swarm.
Manager node-2 demoted in the swarm.

docker node promotedocker node demote是和为了方便的命令docker node update --role managerdocker node update --role worker分别。

在群集节点上安装插件

仅限边缘:此选项仅在 Docker CE Edge 版本中可用。请参阅 Docker CE Edge。

如果您的 swarm 服务依赖于一个或多个插件,则这些插件需要在可能部署服务的每个节点上可用。您可以在每个节点上手动安装插件或编写安装脚本。在 Docker 17.07 及更高版本中,您也可以使用 Docker API 以类似于全局服务的方式部署插件,只需指定一个PluginSpec而不是一个 ContainerSpec

注意:目前没有办法使用 Docker CLI 或 Docker Compose 将插件部署到 swarm。另外,从私有存储库安装插件是不可能的。

PluginSpec是由插件开发人员定义的。要将插件添加到所有 Docker 节点,请使用service/createAPI,并传递在中PluginSpec定义的 API TaskTemplate

离开群

docker swarm leave在节点上运行命令将其从群集中删除。

例如,要将群体留在工作者节点上:

$ docker swarm leave

Node left the swarm.

当一个节点离开群集时,Docker 引擎停止以群集模式运行。Orchestrator 不再将任务安排到节点。

如果节点是经理节点,您将收到有关维持法定人数的警告。要覆盖警告,请传递该--force标志。如果最后一个管理器节点离开群集,则群集变得不可用,要求您采取灾难恢复措施。

有关维护仲裁和灾难恢复的信息,请参阅 Swarm 管理指南。

节点离开群集后,可以docker node rm在管理器节点上运行该命令以从节点列表中删除该节点。

例如:

$ docker node rm node-2

了解更多

  • 群体管理指南
  • Docker 引擎命令行参考
  • Swarm模式教程

指导,群体模式,节点

引擎 | 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.使用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