WordPress + MySQL + Redis + Nginx Stack

Production-style WordPress Docker Compose stack with MySQL for content storage, Redis for caching, and Nginx as the web entrypoint.

yaml

docker-compose.yml

services:
  mysql:
    image: mysql:8
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - mysql_data:/var/lib/mysql
  redis:
    image: redis:8-alpine
    restart: unless-stopped
    command: redis-server --appendonly yes --requirepass ${REDIS_PASSWORD}
    volumes:
      - redis_data:/data
  wordpress:
    image: wordpress:6
    restart: unless-stopped
    depends_on:
      - mysql
      - redis
    environment:
      WORDPRESS_DB_HOST: mysql:3306
      WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
      WORDPRESS_DB_USER: ${MYSQL_USER}
      WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
      - ./wordpress_data:/var/www/html
  nginx:
    image: nginx:1-alpine
    restart: unless-stopped
    depends_on:
      - wordpress
    command:
      - /bin/sh
      - "-c"
      - |
        cat <<'EOF' >/etc/nginx/conf.d/default.conf
        server {
          listen 80;
          client_max_body_size 64m;
          location / {
            proxy_pass http://wordpress:80;
            proxy_set_header Host $$host;
            proxy_set_header X-Real-IP $$remote_addr;
            proxy_set_header X-Forwarded-For $$proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $$scheme;
          }
        }
        EOF
        exec nginx -g 'daemon off;'
    ports:
      - ${WORDPRESS_HTTP_PORT}:80
volumes:
  mysql_data:
  redis_data:

.ENV

.env example

MYSQL_ROOT_PASSWORD=changeme123
MYSQL_DATABASE=wordpress
MYSQL_USER=wordpress
MYSQL_PASSWORD=changeme123
REDIS_PASSWORD=changeme123
WORDPRESS_HTTP_PORT=8080

deployment

Quick Start

  1. Create a working directory named after the service.
  2. Copy the compose file and generated `.env` into that directory.
  3. Review the variables and replace placeholders with real values.
  4. Run `docker compose up -d`.
mkdir wordpress-mysql-redis-nginx-stack
cd wordpress-mysql-redis-nginx-stack
# create docker-compose.yml
# create .env
docker compose up -d