Using Docker Compose to speed up WordPress development
( 19 Articles)
Using Docker Compose to speed up your WordPress development.
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:
WIth Docker, you DO NOT need to use XAMPP, WampServer… or manually install PHP, Apache (or Nginx), MySQL on your computer.
1. Create the project folder:
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:5.7 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.5.3-php7.2-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 to 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:
Then you should see some output like this in your console window:
2. Now launch your browser and go to http://localhost:
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.