版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sureSand/article/details/82155030
默认已经按照上一篇搭好了swarm mode的环境:
swarm mode集群搭建及简单概念
关掉所有的service:
docker service rm nginx test1
使用stack将service打包分组,这里和docker-compose非常相似,编辑一个service.yml
version: "3.4"
services:
alpine:
image: alpine #创建镜像
command: #执行的命令
- "ping"
- "www.baidu.com"
networks: #使用的网络
- "myself-overlay"
deploy: #部署的参数
replicas: 2 #副本数量
restart_policy: #重启策略
condition: on-failure
resources: #资源配置
limits:
cpus: "0.1"
memory: 50M
depends_on: #服务依赖
- nginx
nginx:
image: nginx
networks:
- "myself-overlay"
ports:
- "8080:80"
networks:
myself-overlay:
external: true
然后部署
docker stack deploy -c service.yml test
访问对应ip:port返回nginx首页