WordPress + MySQL Docker Compose Example
WordPress with a MySQL backend, health-gated startup, private backend network, and persistent volumes.
The compose.yaml
name: wordpress
services:
wordpress:
image: wordpress:6-php8.3-apache
restart: unless-stopped
ports:
- 8080:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp
WORDPRESS_DB_PASSWORD: ${WORDPRESS_DB_PASSWORD}
WORDPRESS_DB_NAME: wordpress
volumes:
- wp_data:/var/www/html
networks:
- frontend
- backend
depends_on:
db:
condition: service_healthy
healthcheck:
test:
- CMD-SHELL
- curl -f http://localhost/ || exit 1
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
logging:
driver: json-file
options:
max-size: 10m
max-file: '3'
db:
image: mysql:8.4
restart: unless-stopped
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wp
MYSQL_PASSWORD: ${WORDPRESS_DB_PASSWORD}
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
volumes:
- db_data:/var/lib/mysql
networks:
- backend
healthcheck:
test:
- CMD-SHELL
- mysqladmin ping -h localhost
interval: 30s
timeout: 10s
retries: 3
start_period: 20s
logging:
driver: json-file
options:
max-size: 10m
max-file: '3'
networks:
frontend: {}
backend:
internal: true
volumes:
wp_data: {}
db_data: {}
Start it up
# Validate the configuration (does not start anything):
docker compose -f compose.yaml config
# Pull images and start in the background:
docker compose -f compose.yaml pull
docker compose -f compose.yaml up -d
# Check status and follow logs:
docker compose -f compose.yaml ps
docker compose -f compose.yaml logs -f
# Stop and remove (named volumes are kept):
docker compose -f compose.yaml down
Services
- wordpress — wordpress:6-php8.3-apache
- db — mysql:8.4
Security notes
- warningNo memory limitSet a memory limit sized to the workload (e.g. `mem_limit: 512m`).
- warningNo memory limitSet a memory limit sized to the workload (e.g. `mem_limit: 512m`).
Open the template in the generator to apply one-click hardening.
Practice in Docker Academy
FAQ
How do I run this WordPress + MySQL Docker Compose file?
Save it as compose.yaml, then run `docker compose up -d`. Validate first with `docker compose config` and follow logs with `docker compose logs -f`.
Do I need a version field in the WordPress + MySQL Compose file?
No — modern Docker Compose does not require a top-level version field, and this example does not include one.
How do I customize this WordPress + MySQL template?
Open it in the free Docker Compose Generator to change images, ports, volumes, networks, environment variables, and health checks visually, then download your compose.yaml.
Independent educational example. "Docker" is a trademark of Docker, Inc. Review and adapt before using in production.