Deploying and Managing Services at Scale with Docker Swarm
92%
Healthchecks and Restart Policies
To make our deployment more stable, we can also add other configurations like the healthcheck, restart policy and the failure action to the docker-compose.yml file:
cat < docker-compose.yml
version: '3.9'
services:
db:
image: mysql:9.6.0
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD_FILE: /run/secrets/db_root_password
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_root_password
- db_password
networks:
- wordpress-network
deploy:
placement:
constraints:
- node.role==manager
resources:
limits:
cpus: '1'
memory: 800M
reservations:
cpus: '0.5'
memory: 500M
update_config:
parallelism: 1
delay: 10s
order: start-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
wordpress:
depends_on:
- db
image: wordpress:6.9.1-apache
ports:
- "8000:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD_FILE: /run/secrets/db_password
secrets:
- db_password
networks:
- wordpress-network
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:80"]
interval: 1m30s
timeout: 10s
retries: 3
deploy:
placement:
constraints:Painless Docker - 2nd Edition
A Comprehensive Guide to Mastering Docker and its EcosystemEnroll now to unlock all content and receive all future updates for free.
Unlock now  $31.99$25.59Learn More
Hurry! This limited time offer ends in:
To redeem this offer, copy the coupon code below and apply it at checkout:
