Docker Stack简介及使用
Docker Stack简介及使用
1.简介
Docker Compose的缺点是不能在分布式多服务器上使用,Docker swarm的缺点是不能同时编排多个服务,所以才有了Docker Stack,可以在分布式多服务器上同时编排多个服务。
2.使用实例
1.准备docker-compose文件
本地准备两个镜像后,编写compose文件/root/docker-compose.yml:
version: "3.9"
services:
service1:
image: "masonzhang/service1:V1"
deploy:
replicas: 2
ports:
- "8080:8080"
service2:
image: "masonzhang/service2:V1"
deploy:
replicas: 3
ports:
- "8081:8081"
2.swarm集群搭建
可参考:docker swarm安装使用
3.stack部署
$ docker stack deploy myapps --compose-file=/root/docker-compose.yml
4.stack其他操作
查看所有stack的信息
$ docker stack ls
NAME SERVICES ORCHESTRATOR
myapps 2 Swarm
查看某个stack中的所有任务信息
$ docker stack ps myapps
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE
tvvujrf3qcr1 myapps_service1.1 masonzhang/service1:V1 node1 Running Running 46 seconds ago
igjeydmmvzzm myapps_service1.2 masonzhang/service1:V1 manager Running Running 46 seconds ago
7p5c96eplwl3 myapps_service2.1 masonzhang/service2:V1 node1 Running Running 34 seconds ago
7shglsajip5d myapps_service2.2 masonzhang/service2:V1 manager Running Running 39 seconds ago
upo0mr7j9tn1 myapps_service2.3 masonzhang/service2:V1 node2 Running Preparing 41 seconds ago
查看某个stack中的所有服务信息
$ docker stack services myapps
ID NAME MODE REPLICAS IMAGE PORTS
icz3kjn0skb3 myapps_service1 replicated 2/2 masonzhang/service1:V1 *:8080->8080/tcp
myuzlwnrxag4 myapps_service2 replicated 3/3 masonzhang/service2:V1 *:8081->8081/tcp
移除stack
docker stack rm myapps