Local WordPress development has traditionally meant tools like MAMP, WAMP, XAMPP, or Local by Flywheel — each wrapping a web server, PHP, and MySQL into a package that runs on your machine.
Docker offers a more powerful alternative: containerised development environments that precisely match your production server, are version-controlled alongside your code, work consistently across Mac, Windows, and Linux, and can be set up or torn down in seconds.
This guide walks through setting up a complete WordPress development environment with Docker — using docker-compose to orchestrate WordPress, MySQL, and phpMyAdmin containers.
docker-compose.yml defines the entire development environment. It lives in your project repository — any team member clones the repo and runs docker-compose up to get an identical environment.Install before starting:
Verify installation:
docker --version
docker-compose --version
my-wordpress-project/
docker-compose.yml
.env
wordpress/ (will be created on first run)
mysql-data/ (will be created on first run)
themes/ (your custom theme files)
plugins/ (your custom plugin files)
.gitignore
Create docker-compose.yml in your project root:
version: '3.8'
services:
# MySQL Database
mysql:
image: mysql:8.0
container_name: ${PROJECT_NAME}-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
# WordPress
wordpress:
image: wordpress:6.4-php8.1-apache
container_name: ${PROJECT_NAME}-wordpress
restart: unless-stopped
depends_on:
- mysql
ports:
- "${WORDPRESS_PORT:-8080}:80"
environment:
WORDPRESS_DB_HOST: mysql:3306
WORDPRESS_DB_NAME: ${MYSQL_DATABASE}
WORDPRESS_DB_USER: ${MYSQL_USER}
WORDPRESS_DB_PASSWORD: ${MYSQL_PASSWORD}
WORDPRESS_DEBUG: 1
WORDPRESS_CONFIG_EXTRA: |
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
define('SCRIPT_DEBUG', true);
volumes:
- ./wordpress:/var/www/html
- ./themes:/var/www/html/wp-content/themes/my-theme
- ./plugins:/var/www/html/wp-content/plugins/my-plugin
networks:
- wordpress-network
# phpMyAdmin — database management UI
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: ${PROJECT_NAME}-phpmyadmin
restart: unless-stopped
depends_on:
- mysql
ports:
- "${PHPMYADMIN_PORT:-8081}:80"
environment:
PMA_HOST: mysql
PMA_USER: ${MYSQL_USER}
PMA_PASSWORD: ${MYSQL_PASSWORD}
networks:
- wordpress-network
networks:
wordpress-network:
driver: bridge
.env so credentials stay out of version control.Create .env in your project root with your environment variables:
# Project name (used for container names)
PROJECT_NAME=my-wordpress-project
# Database credentials
MYSQL_ROOT_PASSWORD=rootpassword_change_this
MYSQL_DATABASE=wordpress
MYSQL_USER=wordpress_user
MYSQL_PASSWORD=wordpress_password_change_this
# Port mappings
WORDPRESS_PORT=8080
PHPMYADMIN_PORT=8081
.env to .gitignore — never commit credentials:.env
mysql-data/
wordpress/wp-content/uploads/
Commit a .env.example with placeholder values instead so teammates know what to configure.
# Start all containers (detached mode)
docker-compose up -d
# Start and view logs in real time
docker-compose up
# Stop containers (preserves data)
docker-compose stop
# Stop and remove containers (preserves volumes/data)
docker-compose down
# Stop and remove everything including volumes (destroys all data)
docker-compose down -v
On first start, Docker downloads the WordPress, MySQL, and phpMyAdmin images (~400MB total), creates the directories, initialises MySQL, and starts all three containers. This takes 1–3 minutes on first run. Subsequent starts take about 5 seconds.
http://localhost:8080 in your browserhttp://localhost:8080/wp-adminAccess phpMyAdmin at http://localhost:8081 (login with the MySQL user credentials from .env).
The docker-compose.yml above mounts local directories into the container:
volumes:
- ./themes:/var/www/html/wp-content/themes/my-theme
- ./plugins:/var/www/html/wp-content/plugins/my-plugin
How to use this:
./themes/ on your local machine/var/www/html/wp-content/themes/my-theme# Execute WP-CLI commands inside the WordPress container
docker-compose exec wordpress wp --allow-root plugin list
docker-compose exec wordpress wp --allow-root core version
docker-compose exec wordpress wp --allow-root user list
# Install and activate a plugin
docker-compose exec wordpress wp --allow-root plugin install woocommerce --activate
# Export database
docker-compose exec wordpress wp --allow-root db export - > backup.sql
# Import database
docker-compose exec -T wordpress wp --allow-root db import - < backup.sql
The --allow-root flag is required because Docker containers run commands as root by default.
Create a convenience alias (optional):
# In your ~/.bashrc or ~/.zshrc
alias wpdocker='docker-compose exec wordpress wp --allow-root'
# Usage:
wpdocker plugin list
wpdocker post generate --count=10
Override PHP settings by mounting a custom php.ini:
Create config/php.ini:
[PHP]
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 300
memory_limit = 256M
display_errors = On
error_reporting = E_ALL
Add to docker-compose.yml under WordPress volumes:
volumes:
- ./config/php.ini:/usr/local/etc/php/conf.d/custom.ini
Restart containers: docker-compose restart
For a setup closer to many production environments, replace Apache with Nginx and PHP-FPM:
services:
nginx:
image: nginx:alpine
container_name: ${PROJECT_NAME}-nginx
ports:
- "${WORDPRESS_PORT:-8080}:80"
volumes:
- ./wordpress:/var/www/html
- ./config/nginx.conf:/etc/nginx/conf.d/default.conf
depends_on:
- php
networks:
- wordpress-network
php:
image: wordpress:6.4-php8.1-fpm
container_name: ${PROJECT_NAME}-php
environment:
# Same WordPress env vars as before
volumes:
- ./wordpress:/var/www/html
networks:
- wordpress-network
With config/nginx.conf:
server {
listen 80;
root /var/www/html;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
To develop locally against a copy of an existing production site:
# 1. Export production database
# On production server (via WP-CLI or phpMyAdmin):
wp db export production.sql
# 2. Copy production uploads
rsync -avz user@production:/var/www/html/wp-content/uploads/ ./wordpress/wp-content/uploads/
# 3. Start Docker environment
docker-compose up -d
# 4. Import the database
docker-compose exec -T wordpress wp --allow-root db import - < production.sql
# 5. Update URLs for local environment
docker-compose exec wordpress wp --allow-root search-replace \
'https://production-domain.com' \
'http://localhost:8080' \
--all-tables
# 6. Reset admin password for local use
docker-compose exec wordpress wp --allow-root user update 1 \
--user_pass=local_password --skip-email
| Factor | Docker | Local by Flywheel |
|---|---|---|
| Setup complexity | Medium | Easy |
| Environment control | Full | Good |
| Production parity | Excellent | Good |
| Team consistency | Excellent (via docker-compose.yml) | Good |
| WP-CLI integration | Manual | Built-in |
| GUI | No | Yes |
| Resource usage | Lower | Higher |
| Learning curve | Steeper | Gentle |
Use Docker when: Team consistency matters, you need precise PHP/MySQL version control, you want environment definitions in version control, or you're comfortable with the command line.
Use Local when: You want the simplest possible setup, you prefer a GUI over CLI, or you're the sole developer on a project.
docker-compose exec wordpress wp --allow-root db export - > backup-$(date +%Y%m%d).sql backs up the database to your local machine. For persistent backups, add a volume mount in docker-compose.yml for the MySQL data directory (already done in our setup with ./mysql-data).
.env file (e.g., one project on port 8080, another on 8082). Each project has its own containers, network, and database — completely isolated.
docker-compose exec wordpress wp --allow-root core update. The official WordPress Docker image is updated regularly. To pull the latest image, run docker-compose pull followed by docker-compose up -d.
docker-compose down -v and lose my data?
-v flag removes Docker volumes — including your mysql-data/ directory. Your database and WordPress files are permanently deleted. This is why you should regularly run docker-compose exec wordpress wp --allow-root db export to back up. Recovering requires restoring from your last backup.
pecl install xdebug in an entrypoint script. This is one of Docker's biggest advantages — you can configure debugging tools without affecting your host machine's PHP installation.
Docker is an investment in developer discipline — it takes more initial setup than Local but delivers superior environment consistency, team reproducibility, and production parity. For development teams, agency workflows with multiple projects, or developers who value infrastructure-as-code principles, Docker is the professional standard.
The docker-compose.yml in this guide is a complete, production-ready starting point. Fork it, add your project's specific configuration, commit it to your repository, and your entire team's development environment is a single docker-compose up away.
Need help setting up Docker WordPress environments for your team? We build custom Docker configurations, CI/CD pipelines, and development workflows for enterprise WordPress projects.
Contact us today and we'll sort it out.