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