1 准备yml文件
version:docker编排任务的版本,参考官方说明,这个不是自己定义的,,,,
image:指定镜像
volumes:挂载日志目录,如果宿主机上文件夹不存,启动时会报错:invalid mount config for type…
ports:映射端口号,注意多个service的端口号不要相同
replicas:镜像数
placement.constraints:指定工作节点,对应的是:[node.role == manager]
文档:
version: '3'services: test01: image: 192.168.20.201:5000/ipweb volumes: - /home/log:/home/log networks: - central ports: - 8088:8080 deploy: replicas: 3 placement: constraints: [node.role == worker] test02: image: registry.cn-hangzhou.aliyuncs.com/goldleaf/test:ipweb volumes: - /home/log:/home/log networks: - central ports: - 8089:8080 deploy: replicas: 3 placement: constraints: [node.role == worker]networks: central: external: name: central
2 编排服务
2-1 启动
docker stack deploy -c docker-stack.yml gh
2-2 查看所有stack
docker stack ls
2-3 查看某一stack中的所有服务
docker stack services gh
3 访问测试
curl 192.168.20.201:8088curl 192.168.20.201:8089