docker-compose.yml相关字段
- ENTRYPOINT_MODE 有vip模式和dnssr模式,vip模式就是使用多个容器统一的虚拟ip,dnsrr就是使用真实的IP,然后轮询ip,默认使用vip模式
- MODE 一种是global、一种是replicated,前者不支持横向扩展,后者支持。
- PLACEMENT 指定容器部署的节点、操作系统等等。
- RESOURCES 主要是做一些CPU、内存等资源的限制
- RESTART_POLICY 用于设定容器自动重启的条件
- update_config 用于更新时候的配置
使用docker-compose.yml在swarm上部署
version: '3'
services:
web:
image: wordpress
ports:
- 8080:80
depends_on:
- mysql
environment:
WORDPRESS_DB_HOST: mysql
WORDPRESS_DB_PASSWORD: root
networks:
- wordpress-overlay
deploy:
mode: replicated
replicas: 3
restart_policy:
condition: on-failure
delay: 5s
max_attempts: 3
update_config:
parallelism: 1
delay: 10s
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: wordpress
volumes:
- mysql-data:/var/lib/mysql
networks:
- wordpress-overlay
deploy:
mode: global
placement:
constraints:
- node.role == manager
volumes:
mysql-data:
networks:
wordpress-overlay:
driver: overlay
配置部署
docker stack deploy -c docker-compose.yml wordpress
查看分布
[vagrant@swarm-manager wordpress-overlay]$ docker stack services wordpress
ID NAME MODE REPLICAS IMAGE PORTS
gzhzyuo71ycz wordpress_web replicated 3/3 wordpress:latest *:8080->80/tcp
v2lsqkq0sjr3 wordpress_mysql global 1/1 mysql:5.7
使用如下三个链接都是可以访问的
http://192.168.205.10:8080
http://192.168.205.11:8080
http://192.168.205.12:8080
销毁stack
docker stack rm wordpress