目錄 搜尋
Compose About 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 bundle docker-compose config docker-compose create docker-compose down docker-compose events docker-compose exec docker-compose help docker-compose images docker-compose kill docker-compose logs docker-compose pause docker-compose port docker-compose ps docker-compose pull docker-compose push docker-compose restart docker-compose rm docker-compose run docker-compose scale docker-compose start docker-compose stop docker-compose top docker-compose unpause docker-compose up Environment file (Compose) Environment variables in Compose Extend services in Compose Frequently asked questions (Compose) Getting started (Compose) Install Compose Link environment variables (deprecated) (Compose) Networking in Compose Overview of Docker Compose Overview of docker-compose CLI Quickstart: Compose and WordPress Rails and PostgreSQL (Compose) Sample apps with Compose Using Compose in production Using Compose with Swarm Engine .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-ng Best 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 network Delete the service (Engine) Deploy a service (Engine) Deploy services to a swarm (Engine) Deprecated Engine features Docker container networking (Engine) Docker overview (Engine) Docker run reference (Engine) Dockerfile reference (Engine) Dockerize an application Drain a node (Engine) Engine FAQ (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.10 Optional Linux post-installation steps (Engine) Overview (Engine) PostgreSQL (Engine) Raft consensus in swarm mode (Engine) Riak (Engine) Run Docker Engine in swarm mode Scale 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 Guide Amazon 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 mounts Troubleshoot 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: CLI Daemon CLI reference (dockerd) (Engine) docker docker attach docker build docker checkpoint docker checkpoint create docker checkpoint ls docker checkpoint rm docker commit docker config docker config create docker config inspect docker config ls docker config rm docker container docker container attach docker container commit docker container cp docker container create docker container diff docker container exec docker container export docker container inspect docker container kill docker container logs docker container ls docker container pause docker container port docker container prune docker container rename docker container restart docker container rm docker container run docker container start docker container stats docker container stop docker container top docker container unpause docker container update docker container wait docker cp docker create docker deploy docker diff docker events docker exec docker export docker history docker image docker image build docker image history docker image import docker image inspect docker image load docker image ls docker image prune docker image pull docker image push docker image rm docker image save docker image tag docker images docker import docker info docker inspect docker kill docker load docker login docker logout docker logs docker network docker network connect docker network create docker network disconnect docker network inspect docker network ls docker network prune docker network rm docker node docker node demote docker node inspect docker node ls docker node promote docker node ps docker node rm docker node update docker pause docker plugin docker plugin create docker plugin disable docker plugin enable docker plugin inspect docker plugin install docker plugin ls docker plugin push docker plugin rm docker plugin set docker plugin upgrade docker port docker ps docker pull docker push docker rename docker restart docker rm docker rmi docker run docker save docker search docker secret docker secret create docker secret inspect docker secret ls docker secret rm docker service docker service create docker service inspect docker service logs docker service ls docker service ps docker service rm docker service scale docker service update docker stack docker stack deploy docker stack ls docker stack ps docker stack rm docker stack services docker start docker stats docker stop docker swarm docker swarm ca docker swarm init docker swarm join docker swarm join-token docker swarm leave docker swarm unlock docker swarm unlock-key docker swarm update docker system docker system df docker system events docker system info docker system prune docker tag docker top docker unpause docker update docker version docker volume docker volume create docker volume inspect docker volume ls docker volume prune docker volume rm docker wait Use the Docker command line (Engine) Engine: Extend Access authorization plugin (Engine) Docker log driver plugins Docker network driver plugins (Engine) Extending Engine with plugins Managed plugin system (Engine) Plugin configuration (Engine) Plugins API (Engine) Volume plugins (Engine) Engine: Security AppArmor 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 Engine Use trusted images Using certificates for repository client verification (Engine) Engine: Tutorials Engine tutorials Network containers (Engine) Get Started Part 1: Orientation Part 2: Containers Part 3: Services Part 4: Swarms Part 5: Stacks Part 6: Deploy your app Machine Amazon Web Services (Machine) Digital Ocean (Machine) docker-machine active docker-machine config docker-machine create docker-machine env docker-machine help docker-machine inspect docker-machine ip docker-machine kill docker-machine ls docker-machine provision docker-machine regenerate-certs docker-machine restart docker-machine rm docker-machine scp docker-machine ssh docker-machine start docker-machine status docker-machine stop docker-machine upgrade docker-machine url Driver 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 Machine Machine Machine CLI overview Machine command-line completion Machine concepts and help Machine overview Microsoft Azure (Machine) Microsoft Hyper-V (Machine) Migrate from Boot2Docker to Machine OpenStack (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) Notary Client configuration (Notary) Common Server and signer configurations (Notary) Getting started with Notary Notary changelog Notary configuration files Running a Notary service Server 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模式教程

上一篇: 下一篇: