Docker for Local WordPress Development

I have used every local WordPress environment: MAMP, WAMP, Local by Flywheel, Vagrant, even raw Apache installations. Docker is the first one that consistently works across machines without surprises.
The docker-compose.yml
My standard WordPress development stack fits in one file:
services:
wordpress:
image: wordpress:latest
ports:
- "8080:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wp
WORDPRESS_DB_PASSWORD: wp
WORDPRESS_DB_NAME: wordpress
volumes:
- ./wp-content/themes/mytheme:/var/www/html/wp-content/themes/mytheme
- ./wp-content/plugins:/var/www/html/wp-content/plugins
db:
image: mariadb:11
environment:
MYSQL_DATABASE: wordpress
MYSQL_USER: wp
MYSQL_PASSWORD: wp
MYSQL_ROOT_PASSWORD: root
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin
ports:
- "8081:80"
environment:
PMA_HOST: db
volumes:
db_data:
Why Docker Wins
The killer feature is reproducibility. The same docker-compose.yml works on macOS, Linux, and Windows. New team member? docker compose up and they have an identical environment in 60 seconds. No “works on my machine” problems.
WP-CLI in Docker
I add a wrapper script for WP-CLI that runs inside the container:
#!/bin/bash
docker compose exec wordpress wp "$@" --allow-root
This lets me run ./wp plugin list or ./wp db export from my host machine while the commands execute inside the container with the correct PHP and database configuration.
The Trade-Off
Docker has a steeper initial learning curve than tools like Local by Flywheel. But once you understand the basics, the flexibility and consistency are worth it. I can spin up WordPress 6.x with PHP 8.3 and MariaDB 11 in seconds, or test against PHP 7.4 and MySQL 5.7 just by changing image tags.
Written by
Adrian Saycon
A developer with a passion for emerging technologies, Adrian Saycon focuses on transforming the latest tech trends into great, functional products.


