Docker-Docker Swarm

1.1 购买服务器

购买3台服务器,所有主机都安装dockerdocker-compose

1.2 Swarm集群产生

compose、machine 和 swarm 是docker 原生提供的三大编排工具。简称docker三剑客。

1、服务器硬件要求

硬件资源 最小配置 推荐配置
CPU 1 CPU 2CPU
内存 1GB 2~4GB
硬盘 20 GB 40GB

2、节点信息

主机名 IP地址 具体说明
docker01 8.134.122.252 swarm-manager节点
docker02 8.134.114.8 swarm-work01节点
docker03 8.134.123.77 swarm-work02节点

3、当前服务器应用状态

4、容器化部署存在问题

  • 怎么保证数据完整性,怎么去管很多微服容器,怎么去更新容器而不影响客户的业务?
  • 如果容器down掉了。怎么自动恢复?

=》解决以上问题,docker-swarm横空出世!!!。==

1.3 安装docker-swarm

1、基本概述

Docker Swarm 和 Docker Compose 一样,都是 Docker 官方容器编排项目,但不同的是,Docker Compose 是一个在单个服务器或主机上创建多个容器的工具,可以将组成某个应该的多个docker容器编排在一起,同时管理。而 Docker Swarm 则可以在多个服务器或主机上创建容器集群服务,其主要作用是把若干台Docker主机抽象为一个整体,并且通过一个入口(docker stack)统一管理这些Docker主机上的各种Docker资源。

stack 是构成特定环境中的 service 集合, 它是自动部署多个相互关联的服务的简便方法,而无需单独定义每个服务。stack file 是一种 yaml 格式的文件,类似于 docker-compose.yml 文件,它定义了一个或多个服务,并定义了服务的环境变量、部署标签、容器数量以及相关的环境特定配置等。

2、官方文档:https://docs.docker.com/engine/swarm/

3、Docker Swarm由两部分组成

  • Docker集群:将一个或多个Docker节点组织起来,用户就能以集群的方式进行管理。
  • 应用编排:有一套API用来部署和管理容器。

1.4 管理节点

1、初始化第一个管理节点

advertise-addr和listen-addr这两个参数注解:

  • 前者用来指定其他节点连接m0时的地址。
  • 后者指定承载swarm流量的IP和端口。
  • 创建管理节点,会在本地新建docker网络。

2、manager节点说明

MANAGER STATUS列

  • Leader 意味着该节点是使得群的所有群管理和编排决策的主要管理器节点。
  • Reachable 意味着节点是管理者节点正在参与Raft共识。如果管理节点不可用,则该节点有资格被选为新的管理节点。
  • Unavailable 意味着节点是不能与其他管理器通信的管理器。如果管理器节点不可用,应该将新的管理器节点加入群集,或者将工作器节点升级为管理器。

AVAILABILITY列

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

docker01服务器

注意:IP地址选择的是阿里云服务器的私服!!!

[root@guardwhy01 ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
44443742f9b7   bridge    bridge    local
5f09756231c5   host      host      local
9d85ae8a4d3d   none      null      local
[root@guardwhy01 ~]# docker swarm init --advertise-addr 172.21.251.249:2377 --listen-addr 172.21.251.249:2377
Swarm initialized: current node (ujswj6ys93qhtji45oxszv4zr) is now a manager.

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

    docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-1tattfxbp5ahqz7wk1ha7ycfh 172.21.251.249:2377

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

[root@guardwhy01 ~]# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
44443742f9b7   bridge            bridge    local
c372c3473958   docker_gwbridge   bridge    local
5f09756231c5   host              host      local
jh4ohdal24uo   ingress           overlay   swarm
9d85ae8a4d3d   none              null      local
[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
[root@guardwhy01 ~]# 

3、加入新的节点

Docker Swarm的新节点加入是从管理节点(docker01服务器)获取一长串命令,称为join token,任何加入集群只要执行join token即可加入Swarm集群。

docker02服务器

[root@guardwhy02 ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
475d6f0e7633   bridge    bridge    local
4212954a0f4f   host      host      local
7fb6fab37bee   none      null      local
[root@guardwhy02 ~]# docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-1tattfxbp5ahqz7wk1ha7ycfh 172.21.251.249:2377
This node joined a swarm as a worker.
[root@guardwhy02 ~]# 

如果有新的work节点需要加入,在m0执行命令docker swarm join-token worker即可得到管理work节点的join token

docker01服务器

[root@guardwhy01 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-1tattfxbp5ahqz7wk1ha7ycfh 172.21.251.249:2377

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
[root@guardwhy01 ~]# 

如果有新的管理节点需要加入,在m0执行命令docker swarm join-token manager即可得到管理manager节点的join token

docker01服务器

[root@guardwhy01 ~]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-aw4p1x4xwul0iw1ma2aid49cg 172.21.251.249:2377
[root@guardwhy01 ~]#

docker03服务器

[root@guardwhy03 ~]# docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-aw4p1x4xwul0iw1ma2aid49cg 172.21.251.249:2377
This node joined a swarm as a manager.
[root@guardwhy03 ~]# 

在manager查看所有节点。

docker01服务器

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Ready     Active         Reachable        20.10.7
[root@guardwhy01 ~]# 

1.5 节点相关操作

1、验证节点

master节点

[root@guardwhy01 ~]# docker info


work节点

[root@guardwhy02 ~]# docker info


2、节点权限提升/降低

manager节点降低为worker节点,在manager节点执行如下命令

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Reachable        20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Ready     Active         Leader           20.10.7
[root@guardwhy01 ~]# docker node demote guardwhy03
Manager guardwhy03 demoted in the swarm.
[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Unknown   Active                          20.10.7
[root@guardwhy01 ~]# 

将worker节点提升为manager节点,在manager节点执行如下命令

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Ready     Active                          20.10.7
[root@guardwhy01 ~]# docker node promote guardwhy02 
Node guardwhy02 promoted to a manager in the swarm.
[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active         Reachable        20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Ready     Active                          20.10.7
[root@guardwhy01 ~]# 

3、节点脱离集群

docker03服务器

docker03服务器中,使用以下命令

[root@guardwhy03 ~]# docker swarm leave
Node left the swarm.
[root@guardwhy03 ~]# 

docker01服务器

docker01服务器中,使用以下命令

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Reachable        20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active         Leader           20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Down      Active                          20.10.7
[root@guardwhy01 ~]# 

4、删除脱离集群的节点

删除节点命令: docker node rm 节点名称|节点ID

[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Reachable        20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active         Leader           20.10.7
25wan9kvxtew5m48hvkng8jr5     guardwhy03   Down      Active                          20.10.7
[root@guardwhy01 ~]# docker node rm guardwhy03
guardwhy03
[root@guardwhy01 ~]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Reachable        20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active         Leader           20.10.7
[root@guardwhy01 ~]# 

manager中重新添加worker节点

[root@guardwhy01 ~]# docker swarm join-token worker
To add a worker to this swarm, run the following command:

    docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-1tattfxbp5ahqz7wk1ha7ycfh 172.21.251.249:2377

[root@guardwhy01 ~]#
[root@guardwhy03 ~]# docker swarm join --token SWMTKN-1-2js986t4enexu18fpn5dnticbmx0df9qni5nsfsn6ngykl931s-1tattfxbp5ahqz7wk1ha7ycfh 172.21.251.249:2377
This node joined a swarm as a worker.
[root@guardwhy03 ~]# 

添加成功!!!

5、安装图形界面

docker官方地址: https://hub.docker.com/r/dockersamples/visualizer

拉取基础镜像

注意:要在manager服务器创建容器!!!

docker pull dockersamples/visualizer:latest

运行图形界面镜像

docker run -itd --name visualizer -p 8091:8080 \
-e HOST=8.134.122.252 \
-e PORT=8080 \
-v /var/run/docker.sock:/var/run/docker.sock dockersamples/visualizer:latest

查看运行结果

打开浏览器,点击链接: http://8.134.122.252:8091/

6、Swarm命令小结

常用命令 具体作用
docker swarm init 初始化一个 swarm 群集
docker swarm join 加入群集作为节点或管理器
docker swarm join-token 管理用于加入群集的令牌
docker swarm leave 离开 swarm 群集
docker swarm unlock 解锁 swarm 群集
docker swarm unlock-key 管理解锁钥匙
docker swarm update 更新 swarm 群集

7、node命令小结

常用命令 具体作用
docker node demote 从 swarm 群集管理器中降级一个或多个节点
docker node inspect 显示一个或多个节点的详细信息
docker node ls 列出 swarm 群集中的节点
docker node promote 将一个或多个节点推入到群集管理器中
docker node ps 列出在一个或多个节点上运行的任务,默认为当前节点。
docker node rm 从 swarm 群集删除一个或多个节点
docker node update 更新一个节点

1.6 Docker service

1、docker service命令小结

常用命令 具体作用
docker service create 创建服务
docker service inspect 显示一个或多个服务的详细信息
docker service logs 获取服务的日志
docker service ls 列出服务
docker service rm 删除一个或多个服务
docker service scale 设置服务的实例数量
docker service update 更新服务
docker service rollback 恢复服务至update之前的配置

2、需求实现


2、集群所有的节点都下载nginx基础镜像

docker pull nginx:1.18.0-alpine
docker pull nginx:1.19.3-alpine

3、在docker01服务器(manager节点)中创建overlay网络。

[root@guardwhy01 data]# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
0eb90cd90de7   bridge            bridge    local
c372c3473958   docker_gwbridge   bridge    local
5f09756231c5   host              host      local
jh4ohdal24uo   ingress           overlay   swarm
9d85ae8a4d3d   none              null      local
[root@guardwhy01 data]# docker network create -d overlay nginx-net
yoyo8isxn654fmkeygfsi3nlw
[root@guardwhy01 data]# 

4、创建5个nginx容器的集群

[root@guardwhy01 data]# docker service create --name nginx --network nginx-net -p 80:80 --replicas 5 nginx:1.18.0-alpine 
u0etuzildau4h931nybmjbgtx
overall progress: 5 out of 5 tasks 
1/5: running   [==================================================>] 
2/5: running   [==================================================>] 
3/5: running   [==================================================>] 
4/5: running   [==================================================>] 
5/5: running   [==================================================>] 
verify: Service converged 
[root@guardwhy01 data]# docker node ls
ID                            HOSTNAME     STATUS    AVAILABILITY   MANAGER STATUS   ENGINE VERSION
ujswj6ys93qhtji45oxszv4zr *   guardwhy01   Ready     Active         Leader           20.10.7
sq9x6zrg7u2izo4tzmrffbyz1     guardwhy02   Ready     Active                          20.10.7
pu1ykn1mnx0ptbiw7bjwltrq6     guardwhy03   Ready     Active                          20.10.7
[root@guardwhy01 data]# docker ps -a
CONTAINER ID   IMAGE                             COMMAND                  CREATED         STATUS                            PORTS                                       NAMES
f42ef1d0c1e5   nginx:1.18.0-alpine               "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes                      80/tcp                                      nginx.4.qc3yxnwk3zpeurfg3cj6kfy3t
d4c2fa9dbab0   nginx:1.18.0-alpine               "/docker-entrypoint.…"   3 minutes ago   Up 3 minutes                      80/tcp                                      nginx.2.d89kask69omz214ivu14fduo4
3d648fc53506   dockersamples/visualizer:latest   "/sbin/tini -- node …"   6 hours ago     Up 4 seconds (health: starting)   0.0.0.0:8091->8080/tcp, :::8091->8080/tcp   visualizer
[root@guardwhy01 data]# 

访问链接: http://8.134.122.252:8091/

5、命令查看服务情况。

[root@guardwhy01 data]# docker service ls
ID             NAME      MODE         REPLICAS   IMAGE                 PORTS
u0etuzildau4   nginx     replicated   5/5        nginx:1.18.0-alpine   *:80->80/tcp
[root@guardwhy01 data]#

注意: docker service ls命令只能在manager节点使用,在worker节点无法查看

6、查看服务器容器情况

[root@guardwhy02 home]# docker ps
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS     NAMES
a77fba3447f0   nginx:1.18.0-alpine   "/docker-entrypoint.…"   14 minutes ago   Up 14 minutes   80/tcp    nginx.3.haruvjy8v68otk1cxdkc4rs90
e13fb38a0602   nginx:1.18.0-alpine   "/docker-entrypoint.…"   14 minutes ago   Up 14 minutes   80/tcp    nginx.1.hwedkhibak90mzvh7jt9oaaau
[root@guardwhy02 home]# 

注意: 在manager或者worker节点都可以执行docker ps命令。

7、manager节点只用于管理集群,不部署服务。

[root@guardwhy01 data]# docker node update --availability drain guardwhy01
guardwhy01
[root@guardwhy01 data]# docker ps
CONTAINER ID   IMAGE                             COMMAND                  CREATED       STATUS                    PORTS                                       NAMES
3d648fc53506   dockersamples/visualizer:latest   "/sbin/tini -- node …"   6 hours ago   Up 14 minutes (healthy)   0.0.0.0:8091->8080/tcp, :::8091->8080/tcp   visualizer
[root@guardwhy01 data]# 

访问链接: http://8.134.122.252:8091/

8、将服务缩减为3个容器

[root@guardwhy01 data]# docker service scale nginx=3
nginx scaled to 3
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3:   
verify: Service converged 
[root@guardwhy01 data]# 

访问链接: http://8.134.122.252:8091/

9、升级nginx版本

进入其中一个容器查看nginx的版本信息。

[root@guardwhy02 home]# docker images
REPOSITORY   TAG             IMAGE ID       CREATED        SIZE
nginx        1.18.0-alpine   684dbf9f01f3   2 months ago   21.9MB
nginx        1.19.3-alpine   4efb29ff172a   8 months ago   21.8MB
[root@guardwhy02 home]# docker ps -a
CONTAINER ID   IMAGE                 COMMAND                  CREATED          STATUS          PORTS     NAMES
a77fba3447f0   nginx:1.18.0-alpine   "/docker-entrypoint.…"   29 minutes ago   Up 29 minutes   80/tcp  nginx.3.haruvjy8v68otk1cxdkc4rs90
e13fb38a0602   nginx:1.18.0-alpine   "/docker-entrypoint.…"   29 minutes ago   Up 29 minutes   80/tcp    nginx.1.hwedkhibak90mzvh7jt9oaaau
[root@guardwhy02 home]# docker exec -it e13fb38a0602 sh
/ # nginx -v
nginx version: nginx/1.18.0
nginx version: nginx/1.18.0
/ # exit
[root@guardwhy02 home]# 

更新镜像

注意:更新镜像只能在manager节点使用。

[root@guardwhy01 data]# docker service update --image nginx:1.19.3-alpine nginx
nginx
overall progress: 3 out of 3 tasks 
1/3: running   [==================================================>] 
2/3: running   [==================================================>] 
3/3: running   [==================================================>] 
verify: Service converged 
[root@guardwhy01 data]# 

更新镜像以后,查看结果!!!

添加或者更新一个对外端口

[root@guardwhy01 data]# docker service update --publish-add 8087:80 nginx
nginx
overall progress: 5 out of 5 tasks 
1/5: running   [==================================================>] 
2/5: running   [==================================================>] 
3/5: running   [==================================================>] 
4/5: running   [==================================================>] 
5/5: running   [==================================================>] 
verify: Service converged 
[root@guardwhy01 data]# 

访问链接: http://8.134.122.252:8087/

10、删除服务

[root@guardwhy01 data]# docker network ls
NETWORK ID     NAME              DRIVER    SCOPE
0eb90cd90de7   bridge            bridge    local
c372c3473958   docker_gwbridge   bridge    local
5f09756231c5   host              host      local
jh4ohdal24uo   ingress           overlay   swarm
yoyo8isxn654   nginx-net         overlay   swarm
9d85ae8a4d3d   none              null      local
[root@guardwhy01 data]# docker service rm nginx
nginx
[root@guardwhy01 data]# docker network rm nginx-net
nginx-net
[root@guardwhy01 data]# docker service ls
ID        NAME      MODE      REPLICAS   IMAGE     PORTS
[root@guardwhy01 data]# 

1.7 Docker stack

1、docker stack命令小结

常用命令 具体作用
docker stack deploy 部署新的堆栈或更新现有堆栈
docker stack ls 列出现有堆栈
docker stack ps 列出堆栈中的任务
docker stack rm 删除一个或多个堆栈
docker stack services 列出堆栈中的服务

2、在manager节点中创建docker-compose.yml文件

version: '3'
services:
  nginx-web:
    image: nginx:1.19.3-alpine
    container_name: nginx
    networks:
     - nginx-net
    restart: always
    ports:
      - 80:80
    deploy:
      replicas: 5

networks:
  nginx-net:
    driver: overlay

3、运行nginx

[root@guardwhy01 data]# docker stack deploy nginx-stack -c docker-compose.yml
Ignoring unsupported options: restart

Ignoring deprecated options:

container_name: Setting the container name is not supported.

Creating service nginx-stack_nginx-web
[root@guardwhy01 data]# docker service ls
ID             NAME                    MODE         REPLICAS   IMAGE                 PORTS
i8nabdgwztf0   nginx-stack_nginx-web   replicated   5/5        nginx:1.19.3-alpine   *:80->80/tcp
[root@guardwhy01 data]# 

访问链接: http://8.134.122.252:8091/

4、查看NAME中的服务名为:nginx-stack_nginx-web所有容器

[root@guardwhy01 data]# docker service ps nginx-stack_nginx-web
ID             NAME                      IMAGE                 NODE         DESIRED STATE   CURRENT STATE            ERROR     PORTS
j91t0720gitm   nginx-stack_nginx-web.1   nginx:1.19.3-alpine   guardwhy02   Running         Running 11 minutes ago             
5qooi8nxt1xb   nginx-stack_nginx-web.2   nginx:1.19.3-alpine   guardwhy02   Running         Running 11 minutes ago             
r8cdsibuwsec   nginx-stack_nginx-web.3   nginx:1.19.3-alpine   guardwhy03   Running         Running 11 minutes ago             
ze7d0p8m8wx6   nginx-stack_nginx-web.4   nginx:1.19.3-alpine   guardwhy02   Running         Running 11 minutes ago             
itzy9fa87v50   nginx-stack_nginx-web.5   nginx:1.19.3-alpine   guardwhy03   Running         Running 11 minutes ago             
[root@guardwhy01 data]# 

5、删除stack服务,执行以下命令

[root@guardwhy01 data]# docker stack rm nginx-stack
Removing service nginx-stack_nginx-web
Removing network nginx-stack_nginx-net
[root@guardwhy01 data]# 


6、小结

  • networks中也可以不指定driver:overlay,因为docker swarm默认网络类型是overlay。
  • 整个networks都可以不用配置,stack部署时会默认创建网络。定义网络在docker stack deploy时,会先默认创建一个网络。
  • 注意一定要把镜像先拉取到本地然后再执行。

1.8 Stack和Compose区别

  • Docker stack会忽略了构建指令,无法使用stack命令构建新镜像,它是需要镜像是预先已经构建好的。 所以docker-compose更适合于开发场景。
  • Docker Compose是一个Python项目,它使用Docker API规范来操作容器。所以需要安装Docker -compose,以便与Docker一起在计算机上使用。
  • Docker Stack功能包含在Docker引擎中,不需要安装额外的包来使用它。docker stacks 只是swarm mode的一部分。
  • Docker stack不支持基于第2版写的docker-compose.yml ,也就是version版本至少为3。然而Docker Compose对版本为2和3的 文件仍然可以处理。
  • docker stack把docker compose的所有工作都做完了,因此docker stack将占主导地位。对于大多数用户来说,切换到使用docker stack既不困难,也不需要太多的开销。如果是Docker新手,或正在选择用于新项目的技术,请使用docker stack
posted @ 2021-06-20 13:18  guardwhy  阅读(286)  评论(0编辑  收藏  举报