All tools / Docker Compose examples
WordPress with MySQL with Docker Compose
WordPress and its MySQL database with named volumes, starting WordPress only once the database is healthy.
Customize names, versions and passwords →
compose.yaml
services:
wordpress:
image: wordpress:6.8-apache
restart: unless-stopped
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: "change-me"
volumes:
- wordpress-content:/var/www/html
depends_on:
db:
condition: service_healthy
db:
image: mysql:8.4
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: "change-me"
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: "change-me"
volumes:
- wordpress-db:/var/lib/mysql
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1"]
interval: 10s
timeout: 5s
retries: 10
volumes:
wordpress-content:
wordpress-db:
Passwords here are placeholders (change-me). The generator creates random ones for you.
How to use it
Commands
docker compose up -d docker compose ps docker compose logs -f
- Open http://localhost:8080 to finish the WordPress setup. Add the Caddy or Traefik template in front for HTTPS.
Prefer Kubernetes? See the WordPress with MySQL Kubernetes version.