Using Docker Compose to speed up WordPress development
( 21 Articles)
This article is about using Docker Compose to speed up your WordPress development.
Introduction
In the old days, to set up a WordPress project on our local computer, we used to create a new MySQL database, manually download the WordPress zip file from wordpress.org and unzip it, then walk through a bunch of configuration steps. These days, you can still use that method but there’s a new approach that helps us save a lot of time: using Docker. This approach is currently widely used and at this time, the WordPress image on Docker Hub was downloaded more than 500 million times.
In this tutorial, we’ll create a boilerplate WordPress project that is reusable. With it, you can initialize a new local WordPress with only one command:
docker-compose up
With Docker, you DO NOT need to use XAMPP, WampServer… or manually install PHP, Apache (or Nginx), MySQL on your computer.
Prerequisites
You must have Docker Desktop installed and running on your Mac or Windows computer. If not, check out the guides on how to install Docker Desktop for Mac users and Windows users.
Getting Started
1. Create the project folder:
mkdir my_wp
2. Navigate to the project root and create 2 new files docker-compose.yml and uploads.ini as well as an empty folder named wp-content. This folder is where your themes and plugins live in.
├── docker-compose.yml
├── uploads.ini
└── wp-content
3. Add the following to uploads.ini:
file_uploads = On
memory_limit = 128M
upload_max_filesize = 128M
post_max_size = 128M
max_execution_time = 600
4. Add this to docker-compose.yml:
version: "3"
services:
db:
image: mysql:latest
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: abcd1234
MYSQL_USER: admin
MYSQL_PASSWORD: abcd1234
MYSQL_DATABASE: wordpress
wordpress:
depends_on:
- db
image: wordpress:5.9.0-php7.4-apache
ports:
- "80:80"
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: admin
WORDPRESS_DB_PASSWORD: abcd1234
WORDPRESS_DB_NAME: wordpress
WORDPRESS_DEBUG: 1
working_dir: /var/www/html
volumes:
- ./wp-content:/var/www/html/wp-content
- ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini
volumes:
db_data:
How to reuse the boilerplate?
If you have knowledge about Git, just push the my_wp folder with docker-compose.yml, uploads.ini, and wp-content to GitHub, GitLab… and clone it each time you want to start a new project. If you don’t use Git, just copy and paste it somewhere on your computer.
Check It Out
1. Make a new copy of the my_wp folder (to keep the old one clean) and perform this command in the new project root:
docker-compose up
Then you should see some output like this in your console window:

2. Now launch your browser and go to http://localhost:

It works!
Final Words
This tutorial went over the steps of working with Docker compose and WordPress. You can explore more tags and settings on the official WordPress page on Docker Hub.
If you’d like to learn more about Docker and WordPress, take a look at the following articles:
- How to insert 4K images in your WordPress posts
- Using Docker Compose with Node.js and MongoDB
- Docker: How to Name or Rename a Container
- Docker: How to Retag an Image
- WordPress: Show related posts by tags
- Popular websites built with WordPress
You can also check out our Docker topic page for the latest tutorials, examples, tips, and tricks.
Nice post. I learn something totally new and challenging on websites