1、docker stack deploy 简介
docker stack deploy
命令是用于部署一个新的 stack 或更新现有的 stack。Stack 是由一个或多个服务组成的应用程序的描述。它使用 Docker Compose 文件作为输入来定义服务、网络和卷等配置。
在swarm上创建并更新一个compose文件。
注意:
此命令是一个集群管理命令,必须在集群管理器节点上执行。要了解经理和工人,请参阅文档中的Swarm mode部分。
参考文档:https://docs.docker.com/engine/reference/commandline/stack_deploy/
2、docker stack deploy 语法
docker stack deploy [OPTIONS] STACK
3、docker stack deploy 命令
Compose 文件 (--compose-file)
使用指定的Compose文件部署堆栈。deploy命令支持的Compose文件版本为3.0及以上。
docker stack deploy --compose-file docker-compose.yml vossibility Ignoring unsupported options: links Creating network vossibility_vossibility Creating network vossibility_default Creating service vossibility_nsqd Creating service vossibility_logstash Creating service vossibility_elasticsearch Creating service vossibility_kibana Creating service vossibility_ghollector Creating service vossibility_lookupd
Compose文件也可以通过标准输入提供,使用 --compose-file -
参数:
cat docker-compose.yml | docker stack deploy --compose-file - vossibility Ignoring unsupported options: links Creating network vossibility_vossibility Creating network vossibility_default Creating service vossibility_nsqd Creating service vossibility_logstash Creating service vossibility_elasticsearch Creating service vossibility_kibana Creating service vossibility_ghollector Creating service vossibility_lookupd
如果配置分散在多个Compose文件中,例如基本配置和特定环境的覆盖配置,可以使用多个 --compose-file
参数提供:
docker stack deploy --compose-file docker-compose.yml -c docker-compose.prod.yml vossibility Ignoring unsupported options: links Creating network vossibility_vossibility Creating network vossibility_default Creating service vossibility_nsqd Creating service vossibility_logstash Creating service vossibility_elasticsearch Creating service vossibility_kibana Creating service vossibility_ghollector Creating service vossibility_lookupd
可以验证服务是否正确创建:
docker service ls ID NAME MODE REPLICAS IMAGE 29bv0vnlm903 vossibility_lookupd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 4awt47624qwh vossibility_nsqd replicated 1/1 nsqio/nsq@sha256:eeba05599f31eba418e96e71e0984c3dc96963ceb66924dd37a47bf7ce18a662 4tjx9biia6fs vossibility_elasticsearch replicated 1/1 elasticsearch@sha256:12ac7c6af55d001f71800b83ba91a04f716e58d82e748fa6e5a7359eed2301aa 7563uuzr9eys vossibility_kibana replicated 1/1 kibana@sha256:6995a2d25709a62694a937b8a529ff36da92ebee74bafd7bf00e6caf6db2eb03 9gc5m4met4he vossibility_logstash replicated 1/1 logstash@sha256:2dc8bddd1bb4a5a34e8ebaf73749f6413c101b2edef6617f2f7713926d2141fe axqh55ipl40h vossibility_vossibility-collector replicated 1/1 icecrime/vossibility-collector@sha256:f03f2977203ba6253988c18d04061c5ec7aab46bca9dfd89a9a1fa4500989fba
4、命令选项
选项 | 默认 | 描述 |
--compose-file, -c | 指定Compose文件的路径,或使用 "-" 从stdin中读取 | |
--prune | 清理不再使用的服务 | |
--resolve-image | always | 查询注册表以解析镜像的digest和支持的平台(always, changed, never) |
--with-registry-auth | 将注册表的身份验证信息发送给Swarm agents |
5、子命令
命令 | 描述 |
docker stack config | 输出最终的配置文件,进行合并和插值后 |
docker stack deploy | 部署一个新的 stack 或更新现有的 stack |
docker stack ls | 列出 stacks |
docker stack ps | 列出 stack 中的任务 |
docker stack rm | 移除一个或多个 stacks |
docker stack services | 列出 stack 中的服务 |