Setting up a WordPress environment can be a hassle, especially when dealing with different system configurations. Docker simplifies this process by allowing you to create a consistent development environment across machines. In this guide, we’ll walk you through setting up a WordPress environment using Docker, even if you’re a complete beginner.
By the end of this tutorial, you’ll have a fully functional WordPress site running in Docker containers using Docker Compose.
Why Use Docker Instead of Local Solutions?
Many developers use tools like Local by Flywheel, WAMP, and Laravel Valet for WordPress development. While these tools have their merits, Docker provides several advantages:
- Consistency Across Environments: Docker ensures that your development, staging, and production environments are identical, preventing the “it works on my machine” issue.
- Lightweight & Fast: Unlike full-fledged local server stacks, Docker containers are lightweight and don’t require extensive configuration.
- No System Conflicts: Local solutions may interfere with existing software (e.g., conflicting Apache or MySQL versions), whereas Docker isolates dependencies.
- Easy Dependency Management: With Docker, you can define all dependencies in a
docker-compose.ymlfile and spin up an environment instantly. - Portability: You can share your entire development environment with team members using a simple
docker-compose upcommand. - Scalability: Docker makes it easier to transition from a local setup to a cloud-based or production environment.
Compared to tools like:
- Local by Flywheel: While Local is user-friendly, it is GUI-based and less flexible than Docker in terms of configuration and automation.
- WAMP/XAMPP: These traditional local server solutions can be slow and prone to version mismatches, whereas Docker containers ensure the correct software versions every time.
- Laravel Valet: Valet is great for macOS users but lacks the cross-platform consistency and containerization benefits of Docker.
Step 1: Install Docker
Before getting started, ensure that Docker is installed on your machine:
- Windows & macOS: Download and install Docker Desktop.
- Linux: Install Docker using your package manager. For example:
sudo apt update && sudo apt install docker.io docker-compose -yAfter installation, verify that Docker is running by executing:
docker --version
docker-compose --versionStep 2: Create a Docker Compose File
Docker Compose allows you to define multi-container applications easily. Let’s create a docker-compose.yml file to set up WordPress, MySQL, and phpMyAdmin.
1. Create a new project folder and navigate into it:
mkdir wordpress-docker && cd wordpress-docker2. Create a docker-compose.yml file with the following content:
services:
# The site. Accessible via http://localhost:8888
wp:
image: wordpress:latest
container_name: demo_wp
platform: linux/arm64 #linux/amd64 or windows/amd64
depends_on:
- db
ports:
- "8888:80"
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: demo_db
WORDPRESS_DEBUG: true
WORDPRESS_TABLE_PREFIX: wp_
WORDPRESS_CONFIG_EXTRA: |
define('WP_ENVIRONMENT_TYPE', 'local');
define('WP_HOME', 'http://localhost:8888');
define('WP_SITEURL', 'http://localhost:8888');
define('FORCE_SSL_ADMIN', false);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
@ini_set( 'display_errors', 0 );
volumes:
- wordpress_data:/var/www/html
db:
image: mysql #or mariadb
container_name: demo_db
platform: linux/arm64 #linux/amd64 or windows/amd64
ports:
- "13306:3306"
environment:
MYSQL_DATABASE: demo_db
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
MYSQL_ROOT_PASSWORD: root
volumes:
- db_data:/var/lib/mysql
volumes:
wordpress_data:
db_data:This configuration sets up:
- WordPress container exposed on port
8888. - MySQL database with a persistent volume and exposed on port 13306.
- platform: Docker allows to run container on multi-platform builds: ARM and x86. If you have Apple’s M chip you need to define platform as “linux/arm64”
To work with Database you can add phpmyadmin container to the docker config after db in the next way:
phpmyadmin:
image: phpmyadmin/phpmyadmin
container_name: wordpress_phpmyadmin
restart: always
ports:
- "8089:80"
environment:
PMA_HOST: db
MYSQL_ROOT_PASSWORD: root
depends_on:
- dbor you can use external application (which I prefer to use) such as TablePlus with the next configuration:

Most all the times you have project files stored locally on the computer. In that case you can forward local volumes to the container. So then you can add next configuration to the docker-compose.yml file:
services:
# The site. Accessible via http://localhost:8888
wp:
volumes:
- wordpress_data:/var/www/html
- ./wp-content:/var/www/html/wp-contentWordPress will be defined in image: wordpress:latest parameter. Of course you have an option to not use Docker image but instead of this you have to forward full local volume:
services:
# The site. Accessible via http://localhost:8888
wp:
volumes:
- ./:/var/www/htmlStep 3: Start the Containers
With the docker-compose.yml file ready, run the following command:
docker-compose up -dThis will pull the necessary images and start the containers in the background. You can check if everything is running with:
docker psOr you can open Docker Desktop app to check the containers
Step 4: Access WordPress
Once the containers are running, open your browser and visit: http://localhost:8888
Follow the WordPress installation steps by entering the database credentials from the docker-compose.yml file:
- Database Name: demo_db
- Username: wordpress
- Password: wordpress
- Database Host: db
After completing the setup, you’ll have a fully functional WordPress site!
Step 5: Manage Your Docker Environment
To stop and removes containers:
docker-compose downTo restart the environment:
docker-compose up -dTo view logs for debugging:
docker logs demo_wpOnce you have changed configuration docker-compose.yml file you need to rebuild the images:
docker compose up -d --buildStep 6: Common Troubleshooting Tips
1. Port Conflicts: If port 8888 is in use, change it in docker-compose.yml (e.g., 9090:80).
2. Database Connection Issues: Ensure MySQL is running and the credentials match.
3. Checking Logs: Use docker logs <container_id> to diagnose errors.
Want the Full Production-Ready Docker Setup?
I wrote this beginner’s guide to help you understand the basics of running WordPress with Docker. However, if you want to go from “it kind of works” to a professional, reproducible, production-grade environment, I created something much more complete for you.
🚀 WordPress + Docker: A Practical Guide to Production-Ready Development
72-page complete guide + full GitHub repository
- ✅ Both Apache + mod_php and Nginx + PHP-FPM stacks
- ✅ Custom PHP-FPM Dockerfiles with all extensions and optimizations
- ✅ Redis object caching, cron jobs, and Mailpit email testing
- ✅ Persistent database + safe volume setup
- ✅ 6 ready-to-clone GitHub templates (lite, advanced, Alpine, multi-PHP)
- ✅ Developer Toolkit with 50+ daily commands
Launch an identical, production-ready WordPress environment with just one command. Get the Full Guide + GitHub Repo → $29
Instant download • Lifetime updates • 6 complete starter templates included
This is the exact setup I use for all my client projects and agency work. It eliminates “works on my machine” problems and saves dozens of hours.
Conclusion
You’ve successfully set up a WordPress environment using Docker! This setup makes local development faster, consistent, and portable. As a next step, you can explore:
- Customizing the WordPress theme and plugins.
- Deploying your setup to production.
Let us know in the comments if you have any questions or run into any issues. Happy coding! 🚀
