docker.recipes

WordPress + MySQL + Redis

beginner

ready WordPress setup with MySQL database and Redis object caching for improved performance.

Overview

WordPress powers over 40% of all websites worldwide, making it the most dominant content management system on the internet. Born in 2003 as a blogging platform, WordPress has evolved into a versatile CMS capable of handling everything from simple blogs to complex e-commerce sites and enterprise applications. Its success stems from an enormous plugin ecosystem of over 60,000 extensions, thousands of themes, and a user-friendly interface that makes website creation accessible to non-technical users while remaining powerful enough for developers. This stack combines WordPress with MySQL 8.0 and Redis to create a high-performance content management platform. MySQL serves as WordPress's primary database, storing posts, pages, user data, and configuration settings with ACID compliance and reliable performance. Redis acts as an object cache, dramatically reducing database queries by storing frequently accessed data in memory. This combination can reduce page load times by 50-80% compared to a basic WordPress installation, especially under heavy traffic loads. This configuration is ideal for content creators, marketing teams, and businesses running WordPress sites that experience moderate to high traffic. The Redis caching layer makes it particularly valuable for news sites, popular blogs, and e-commerce stores where page speed directly impacts user experience and search engine rankings. Small agencies and freelance developers will appreciate the professional-grade performance without the complexity of enterprise caching solutions.

Key Features

  • Gutenberg block editor for visual content creation with drag-and-drop functionality
  • Over 60,000 plugins including WooCommerce, Yoast SEO, and Elementor page builder
  • MySQL InnoDB storage engine with full ACID compliance and crash recovery
  • Redis object caching reduces database queries by up to 90% for repeated content
  • WordPress REST API enables headless CMS functionality and mobile app integration
  • MySQL Group Replication support for high availability deployments
  • Sub-millisecond Redis response times for session storage and page caching
  • WordPress multisite capability for managing multiple websites from single installation

Common Use Cases

  • 1High-traffic blogs and news websites requiring fast page load times
  • 2E-commerce stores using WooCommerce with product catalogs and customer data
  • 3Corporate websites with frequent content updates and multiple editors
  • 4Digital marketing agencies managing multiple client WordPress sites
  • 5Membership sites with user-generated content and community features
  • 6Portfolio websites for creative professionals needing media-rich content
  • 7Educational institutions running course management and student portals

Prerequisites

  • Docker and Docker Compose installed on host system
  • Minimum 2GB RAM available (WordPress 512MB + MySQL 1GB + Redis 512MB)
  • Port 8080 available for WordPress web interface access
  • Basic familiarity with WordPress admin dashboard and plugin installation
  • Understanding of MySQL database concepts for backup and maintenance
  • .env file with database credentials (MYSQL_ROOT_PASSWORD, MYSQL_USER, MYSQL_PASSWORD, MYSQL_DATABASE)

For development & testing. Review security settings, change default credentials, and test thoroughly before production use. See Terms

docker-compose.yml

docker-compose.yml
1services:
2 wordpress:
3 image: wordpress:latest
4 container_name: wordpress
5 restart: unless-stopped
6 environment:
7 WORDPRESS_DB_HOST: mysql
8 WORDPRESS_DB_USER: ${MYSQL_USER}
9 WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
10 WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
11 volumes:
12 - wordpress_data:/var/www/html
13 ports:
14 - "8080:80"
15 depends_on:
16 - mysql
17 - redis
18 networks:
19 - wordpress-network
20
21 mysql:
22 image: mysql:8.0
23 container_name: wordpress-mysql
24 restart: unless-stopped
25 environment:
26 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
27 MYSQL_DATABASE: ${MYSQL_DATABASE}
28 MYSQL_USER: ${MYSQL_USER}
29 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
30 volumes:
31 - mysql_data:/var/lib/mysql
32 networks:
33 - wordpress-network
34
35 redis:
36 image: redis:alpine
37 container_name: wordpress-redis
38 restart: unless-stopped
39 volumes:
40 - redis_data:/data
41 networks:
42 - wordpress-network
43
44volumes:
45 wordpress_data:
46 mysql_data:
47 redis_data:
48
49networks:
50 wordpress-network:
51 driver: bridge

.env Template

.env
1# MySQL Configuration
2MYSQL_ROOT_PASSWORD=rootpassword
3MYSQL_DATABASE=wordpress
4MYSQL_USER=wordpress
5MYSQL_PASSWORD=changeme

Usage Notes

  1. 1Docs: https://wordpress.org/documentation/
  2. 2Access at http://localhost:8080 - complete installation wizard
  3. 3Install Redis Object Cache plugin, set host to 'redis' in wp-config.php
  4. 4For HTTPS: use Traefik/Caddy reverse proxy with Let's Encrypt
  5. 5Backup: wp-content folder + MySQL dump (mysqldump wordpress > backup.sql)
  6. 6Update: docker compose pull && docker compose up -d

Individual Services(3 services)

Copy individual services to mix and match with your existing compose files.

wordpress
wordpress:
  image: wordpress:latest
  container_name: wordpress
  restart: unless-stopped
  environment:
    WORDPRESS_DB_HOST: mysql
    WORDPRESS_DB_USER: ${MYSQL_USER}
    WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
    WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
  volumes:
    - wordpress_data:/var/www/html
  ports:
    - "8080:80"
  depends_on:
    - mysql
    - redis
  networks:
    - wordpress-network
mysql
mysql:
  image: mysql:8.0
  container_name: wordpress-mysql
  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
  networks:
    - wordpress-network
redis
redis:
  image: redis:alpine
  container_name: wordpress-redis
  restart: unless-stopped
  volumes:
    - redis_data:/data
  networks:
    - wordpress-network

Quick Start

terminal
1# 1. Create the compose file
2cat > docker-compose.yml << 'EOF'
3services:
4 wordpress:
5 image: wordpress:latest
6 container_name: wordpress
7 restart: unless-stopped
8 environment:
9 WORDPRESS_DB_HOST: mysql
10 WORDPRESS_DB_USER: ${MYSQL_USER}
11 WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
12 WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
13 volumes:
14 - wordpress_data:/var/www/html
15 ports:
16 - "8080:80"
17 depends_on:
18 - mysql
19 - redis
20 networks:
21 - wordpress-network
22
23 mysql:
24 image: mysql:8.0
25 container_name: wordpress-mysql
26 restart: unless-stopped
27 environment:
28 MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
29 MYSQL_DATABASE: ${MYSQL_DATABASE}
30 MYSQL_USER: ${MYSQL_USER}
31 MYSQL_PASSWORD: ${MYSQL_PASSWORD}
32 volumes:
33 - mysql_data:/var/lib/mysql
34 networks:
35 - wordpress-network
36
37 redis:
38 image: redis:alpine
39 container_name: wordpress-redis
40 restart: unless-stopped
41 volumes:
42 - redis_data:/data
43 networks:
44 - wordpress-network
45
46volumes:
47 wordpress_data:
48 mysql_data:
49 redis_data:
50
51networks:
52 wordpress-network:
53 driver: bridge
54EOF
55
56# 2. Create the .env file
57cat > .env << 'EOF'
58# MySQL Configuration
59MYSQL_ROOT_PASSWORD=rootpassword
60MYSQL_DATABASE=wordpress
61MYSQL_USER=wordpress
62MYSQL_PASSWORD=changeme
63EOF
64
65# 3. Start the services
66docker compose up -d
67
68# 4. View logs
69docker compose logs -f

One-Liner

Run this command to download and set up the recipe in one step:

terminal
1curl -fsSL https://docker.recipes/api/recipes/wordpress-mysql-redis/run | bash

Troubleshooting

  • Error establishing database connection: Check that mysql container is running with 'docker logs wordpress-mysql' and verify environment variables match between services
  • WordPress installation wizard loops endlessly: Delete wordpress_data volume and restart containers to reset WordPress installation state
  • Redis object cache not working: Install Redis Object Cache plugin from WordPress admin, then add 'define('WP_REDIS_HOST', 'redis');' to wp-config.php
  • MySQL container exits with code 1: Ensure MYSQL_ROOT_PASSWORD is set in environment file and mysql_data volume has correct permissions
  • Site loads slowly despite Redis: Enable Redis object cache in WordPress plugin settings and verify connection with 'docker exec wordpress-redis redis-cli ping'
  • Permission denied errors on uploads: Check that wordpress_data volume has proper ownership with 'docker exec wordpress chown -R www-data:www-data /var/www/html'

Community Notes

Loading...
Loading notes...

Download Recipe Kit

Get all files in a ready-to-deploy package

Includes docker-compose.yml, .env template, README, and license

Ad Space