Docker-compose.yml related fields
- ENTRYPOINT_ Mode includes VIP mode and dnssr mode. VIP mode is to use multiple containers for unified virtual IP. Dnsrr is to use real IP and then poll IP. VIP mode is used by default
- One mode is global and the other is replicated. The former does not support horizontal expansion, and the latter does.
- Placement specifies the node, operating system, and so on for container deployment.
- Resources mainly limits CPU, memory and other resources
- RESTART_ Policy is used to set the conditions for automatic container restart
- update_ Config is used to update the configuration
Deploy on swarm using docker-compose.yml
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
[[email protected] 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
The following three links are accessible
http://192.168.205.10:8080 http://192.168.205.11:8080 http://192.168.205.12:8080
docker stack rm wordpress