back home

Begin WordPress Docking Sequence – Open the bay doors…

Written by Bunkers on February 24, 2017

I got interested in using Docker partly because of the hype but partly because my development environment usually involved running one or more virtual machines. Vagrant has been a great tool for managing these, but Docker represented another step forward. Creating and disposing of Docker containers made the machines that run the components of an application both lightweight but also disposable. Done right they would be simple units allowing for reuse in other projects.

At work I have some internal tools run using Docker containers. A Sinopia NPM repository and an instance of Gaps to help people with their Google Groups subscriptions. There's also an OpenVPN container that allows me to have a static IP address white-listed for access to our servers. All of this works ok, but there are a some issues:

To learn more about Docker I needed a project, but I wanted one that would be useful. From day to day I'm developing in a .NET environment. It's not yet .NET Core so it's not really suitable for a beginner project like this. There are options to create containers using Mono, but at the least I'd have to convert our SQL Server database to PostgreSQL or MySQL and then who knows what changes to the code base that would require.

We've developed our website using WordPress and I generally do most updates to it. It's running as WordPress multisite, so isn't a trivial configuration. I've also been using Mercury to have an environment as close to our WP Engine hosting as possible, but recently it's been causing some problems. Most notably the start up does some port forwarding and additions to my hosts file that it now has trouble cleaning up. Not a reason to jump ship (pardon the pun!) in itself, but just another reason to make me want to experiment with creating my development environment using Docker.

To create a development environment that mimics production, I decided to follow the approach in this article WordPress and Docker The Correct Way. It sticks to the principles of creating containers for single use, therefore making them reusable. It also uses all the same technology as Mercury, so it's a comparable environment.

I have deviated from this setup in some ways. Partly to experiment but also because some aspects felt like they should live in different places. You'll see that I create config files during the startup/creation of my file system volume. Others would probably frown upon this, but as far as I can tell it's a lot to do with personal preference. I can articulate a couple of reasons for putting the wp-config.php file in there, so that's good enough for me!

To get started you need the Docker tools up and running. For some time installing Docker Toolbox was the preferred (only available?) way of doing this. It had to create a virtual machine for running Docker Engine. I came across the Dinghy project which used Vagrant to run this virtual machine and provides some other tools to make for a more pleasant experience, and I'd still recommend it. Recently however, the official Docker for Mac (and Windows or course!) entered public beta and is a good option. You'll be fine with whichever you choose, so if you want to follow along, set it up according to instructions. I definitely don't want to write yet another explanation of what Docker is and 'your first container' article. There's a million getting started guides just a web search away. This series of posts is just to document my experiences and to help anyone that may come across the same problems or decisions I did.

And now for a slightly backwards final point. If you're going to be using Docker for local WordPress development, the chances are that you don't want to do what I'm doing! Stop now, and just use the official WordPress containers. But if you want to learn a bit more about Docker, and setup things like multisite, come along for the ride. It'll be bumpy in places but then that makes it more enjoyable, right?