Using Docker for WordPress Development

Over the years my development workflow for WordPress has evolved.  Along with the different operating systems we use.

As a developer, you will undoubtedly be working on any number of projects at any one time. Each project will typically have its own unique configuration settings.   In a WordPress project for instance, your different customer sites may each be installed on different servers, some with different PHP versions or even different web server configuration, for instance some may be configured to use Apache web server, while others use Nginx.

It can be quite difficult to manage your laptop, to enable easy switch over between each environment.

I over the  years, I have written a number of blog posts providing instructions on how to get set up for local development with WordPress

All these solutions work great, but they were always finicky and invariably when you’re constantly moving between environments like I frequently do, it becomes a bit of a chore to continuously having to configure your environment.

Docker to the rescue

Docker removes a lot of this hassle and now makes it incredibly easy to get your environments configured usually taken only a few seconds. Saving a lot of time and frustration.

If haven’t already got docker installed then what are you waiting for?  Check out my docker tutorials to help you to get up to speed quickly.

Docker runs on all popular operating systems so be sure to follow the instructions on the docker website on how to install it on your system.  If you’re using ubuntu as your primary software development machine you may want to check out my guide on how to install docker on ubuntu

Install Docker compose

Docker Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

There are detailed instructions to on the docker compose website to ensure you have the latest version installed.

Install WordPress Via Docker Compose

Once you have Docker and Docker Compose all set up, moving on to the next phase is really simple. There is a quick start Docker Compose script available. Quickstart: Compose and WordPress

These instructions are great if you just want to get a version of WordPress up and running on your machine. However, if you want to build a complete development environment you will need to extend the docker-compose.yml


Get the code

Clone the GitHub repository


Adding phpmyadmin

We’ll enhance the standard WordPress docker-compose.yml by adding a phpmyadmin to help with basic database administration tasks.

We’ll grad the official phpMyAdmin image. link it to our wordpress_db container with the name mysql, expose its port 80 on port 8080 of the host system, and finally sets a couple of environment variables with our mySQL username and password.



Map to local file system

It is possible to store the document root for WordPress on the host filesystem using a Docker data volume to share files between the host and the container.

We will also map the WordPress file system to our local drive, in order to be able to carry both themes and plugin development.

The WordPress Docker container is configured to check if /var/www/html is empty or not when it starts and copies files there appropriately.

Using the docker-compose

To use the Docker-compose file, using the terminal window simply change directory to the folder that contains the docker-compose.yaml and use the command docker-compose up -d.

Once the it’s complete, you shoulb be able to open a browser to http://localhost to browse the WordPress and http://localhost:8080/ to browse to phpmyadmin.


Other useful docker-compose commands:


Develop themes and plugins

It is possible to develop specific components for WordPress, like themes and plugins. All it needs is a proper configuration of Volumes in the docker-compose.yml file.

theme development

plugin development


You should have a full WordPress deploy up and running.

You should be able to use the same method to create different version installations of WordPress that you can use for testing purposes, just changing the WordPress version.

running Docker commands to create containers already simplifies application management, docker-compose takes it a step further and allows you to bundle multiple containers within a single working directory.

Follow Me

Gary Woodfine

Helps businesses by improving their technical proficiencies and eliminating waste from the software development pipelines.

A unique background as business owner, marketing, software development and business development ensures that he can offer the optimum business consultancy services across a wide spectrum of business challenges.
Follow Me

Latest posts by Gary Woodfine (see all)

%d bloggers like this: