目录搜索
ComposeAbout versions and upgrading (Compose)ASP.NET Core + SQL Server on Linux (Compose)CLI environment variables (Compose)Command-line completion (Compose)Compose(组成)Compose command-line reference(组合命令行参考)Control startup order (Compose)Django and PostgreSQL (Compose)Docker stacks and distributed application bundles (Compose)docker-compose build(docker-compose构建)docker-compose bundledocker-compose configdocker-compose createdocker-compose downdocker-compose eventsdocker-compose execdocker-compose helpdocker-compose imagesdocker-compose killdocker-compose logsdocker-compose pausedocker-compose portdocker-compose psdocker-compose pulldocker-compose pushdocker-compose restartdocker-compose rmdocker-compose rundocker-compose scaledocker-compose startdocker-compose stopdocker-compose topdocker-compose unpausedocker-compose upEnvironment file (Compose)Environment variables in ComposeExtend services in ComposeFrequently asked questions (Compose)Getting started (Compose)Install ComposeLink environment variables (deprecated) (Compose)Networking in ComposeOverview of Docker ComposeOverview of docker-compose CLIQuickstart: Compose and WordPressRails and PostgreSQL (Compose)Sample apps with ComposeUsing Compose in productionUsing Compose with SwarmEngine.NET Core application (Engine)About images, containers, and storage drivers (Engine)Add nodes to the swarm (Engine)Apply custom metadata (Engine)Apply rolling updates (Engine)apt-cacher-ngBest practices for writing Dockerfiles (Engine)Binaries (Engine)Bind container ports to the host (Engine)Breaking changes (Engine)Build your own bridge (Engine)Configure container DNS (Engine)Configure container DNS in user-defined networks (Engine)CouchDB (Engine)Create a base image (Engine)Create a swarm (Engine)Customize the docker0 bridge (Engine)Debian (Engine)Default bridge networkDelete the service (Engine)Deploy a service (Engine)Deploy services to a swarm (Engine)Deprecated Engine featuresDocker container networking (Engine)Docker overview (Engine)Docker run reference (Engine)Dockerfile reference (Engine)Dockerize an applicationDrain a node (Engine)EngineFAQ (Engine)Fedora (Engine)Get started (Engine)Get started with macvlan network driver (Engine)Get started with multi-host networking (Engine)How nodes work (Engine)How services work (Engine)Image management (Engine)Inspect the service (Engine)Install Docker (Engine)IPv6 with Docker (Engine)Join nodes to a swarm (Engine)Legacy container links (Engine)Lock your swarm (Engine)Manage nodes in a swarm (Engine)Manage sensitive data with Docker secrets (Engine)Manage swarm security with PKI (Engine)Manage swarm service networks (Engine)Migrate to Engine 1.10Optional Linux post-installation steps (Engine)Overview (Engine)PostgreSQL (Engine)Raft consensus in swarm mode (Engine)Riak (Engine)Run Docker Engine in swarm modeScale the service (Engine)SDKs (Engine)Select a storage driver (Engine)Set up for the tutorial (Engine)SSHd (Engine)Storage driver overview (Engine)Store service configuration data (Engine)Swarm administration guide (Engine)Swarm mode key concepts (Engine)Swarm mode overlay network security model (Engine)Swarm mode overview (Engine)Understand container communication (Engine)Use multi-stage builds (Engine)Use swarm mode routing mesh (Engine)Use the AUFS storage driver (Engine)Use the Btrfs storage driver (Engine)Use the Device mapper storage driver (Engine)Use the OverlayFS storage driver (Engine)Use the VFS storage driver (Engine)Use the ZFS storage driver (Engine)Engine: Admin GuideAmazon CloudWatch logs logging driver (Engine)Bind mounts (Engine)Collect Docker metrics with Prometheus (Engine)Configuring and running Docker (Engine)Configuring logging drivers (Engine)Control and configure Docker with systemd (Engine)ETW logging driver (Engine)Fluentd logging driver (Engine)Format command and log output (Engine)Google Cloud logging driver (Engine)Graylog Extended Format (GELF) logging driver (Engine)Journald logging driver (Engine)JSON File logging driver (Engine)Keep containers alive during daemon downtime (Engine)Limit a container's resources (Engine)Link via an ambassador container (Engine)Log tags for logging driver (Engine)Logentries logging driver (Engine)PowerShell DSC usage (Engine)Prune unused Docker objects (Engine)Run multiple services in a container (Engine)Runtime metrics (Engine)Splunk logging driver (Engine)Start containers automatically (Engine)Storage overview (Engine)Syslog logging driver (Engine)tmpfs mountsTroubleshoot volume problems (Engine)Use a logging driver plugin (Engine)Using Ansible (Engine)Using Chef (Engine)Using Puppet (Engine)View a container's logs (Engine)Volumes (Engine)Engine: CLIDaemon CLI reference (dockerd) (Engine)dockerdocker attachdocker builddocker checkpointdocker checkpoint createdocker checkpoint lsdocker checkpoint rmdocker commitdocker configdocker config createdocker config inspectdocker config lsdocker config rmdocker containerdocker container attachdocker container commitdocker container cpdocker container createdocker container diffdocker container execdocker container exportdocker container inspectdocker container killdocker container logsdocker container lsdocker container pausedocker container portdocker container prunedocker container renamedocker container restartdocker container rmdocker container rundocker container startdocker container statsdocker container stopdocker container topdocker container unpausedocker container updatedocker container waitdocker cpdocker createdocker deploydocker diffdocker eventsdocker execdocker exportdocker historydocker imagedocker image builddocker image historydocker image importdocker image inspectdocker image loaddocker image lsdocker image prunedocker image pulldocker image pushdocker image rmdocker image savedocker image tagdocker imagesdocker importdocker infodocker inspectdocker killdocker loaddocker logindocker logoutdocker logsdocker networkdocker network connectdocker network createdocker network disconnectdocker network inspectdocker network lsdocker network prunedocker network rmdocker nodedocker node demotedocker node inspectdocker node lsdocker node promotedocker node psdocker node rmdocker node updatedocker pausedocker plugindocker plugin createdocker plugin disabledocker plugin enabledocker plugin inspectdocker plugin installdocker plugin lsdocker plugin pushdocker plugin rmdocker plugin setdocker plugin upgradedocker portdocker psdocker pulldocker pushdocker renamedocker restartdocker rmdocker rmidocker rundocker savedocker searchdocker secretdocker secret createdocker secret inspectdocker secret lsdocker secret rmdocker servicedocker service createdocker service inspectdocker service logsdocker service lsdocker service psdocker service rmdocker service scaledocker service updatedocker stackdocker stack deploydocker stack lsdocker stack psdocker stack rmdocker stack servicesdocker startdocker statsdocker stopdocker swarmdocker swarm cadocker swarm initdocker swarm joindocker swarm join-tokendocker swarm leavedocker swarm unlockdocker swarm unlock-keydocker swarm updatedocker systemdocker system dfdocker system eventsdocker system infodocker system prunedocker tagdocker topdocker unpausedocker updatedocker versiondocker volumedocker volume createdocker volume inspectdocker volume lsdocker volume prunedocker volume rmdocker waitUse the Docker command line (Engine)Engine: ExtendAccess authorization plugin (Engine)Docker log driver pluginsDocker network driver plugins (Engine)Extending Engine with pluginsManaged plugin system (Engine)Plugin configuration (Engine)Plugins API (Engine)Volume plugins (Engine)Engine: SecurityAppArmor security profiles for Docker (Engine)Automation with content trust (Engine)Content trust in Docker (Engine)Delegations for content trust (Engine)Deploying Notary (Engine)Docker security (Engine)Docker security non-events (Engine)Isolate containers with a user namespace (Engine)Manage keys for content trust (Engine)Play in a content trust sandbox (Engine)Protect the Docker daemon socket (Engine)Seccomp security profiles for Docker (Engine)Secure EngineUse trusted imagesUsing certificates for repository client verification (Engine)Engine: TutorialsEngine tutorialsNetwork containers (Engine)Get StartedPart 1: OrientationPart 2: ContainersPart 3: ServicesPart 4: SwarmsPart 5: StacksPart 6: Deploy your appMachineAmazon Web Services (Machine)Digital Ocean (Machine)docker-machine activedocker-machine configdocker-machine createdocker-machine envdocker-machine helpdocker-machine inspectdocker-machine ipdocker-machine killdocker-machine lsdocker-machine provisiondocker-machine regenerate-certsdocker-machine restartdocker-machine rmdocker-machine scpdocker-machine sshdocker-machine startdocker-machine statusdocker-machine stopdocker-machine upgradedocker-machine urlDriver options and operating system defaults (Machine)Drivers overview (Machine)Exoscale (Machine)Generic (Machine)Get started with a local VM (Machine)Google Compute Engine (Machine)IBM Softlayer (Machine)Install MachineMachineMachine CLI overviewMachine command-line completionMachine concepts and helpMachine overviewMicrosoft Azure (Machine)Microsoft Hyper-V (Machine)Migrate from Boot2Docker to MachineOpenStack (Machine)Oracle VirtualBox (Machine)Provision AWS EC2 instances (Machine)Provision Digital Ocean Droplets (Machine)Provision hosts in the cloud (Machine)Rackspace (Machine)VMware Fusion (Machine)VMware vCloud Air (Machine)VMware vSphere (Machine)NotaryClient configuration (Notary)Common Server and signer configurations (Notary)Getting started with NotaryNotary changelogNotary configuration filesRunning a Notary serviceServer configuration (Notary)Signer configuration (Notary)Understand the service architecture (Notary)Use the Notary client
文字

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

  • 列出群中的节点

  • 检查单个节点

  • 更新节点

  • 离开群

列出节点

要从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-1Joined 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-1node-1

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

添加或删除标签元数据

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

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

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

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

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

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

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

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

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

升级或降级节点

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

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

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

$ docker node promote node-3 node-2Node 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-2Manager 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模式教程

上一篇:下一篇: