WordPress on Autopilot

May 05, 2016 - by Casey Bisson

WordPress, the user-friendly blog-oriented CMS that powers 25% of the web1, is famous for its 5-minute install2, but that's only for a single server with no scalability. Containerization and the Autopilot Pattern change that, however, and now we can deploy a WordPress website and scale it to meet any amount of traffic with a single command. This isn't a PaaS, this is your own WordPress install that you can completely customize with your own themes and plugins.

tl;dr: Try it for yourself right now.

Together with 10up, a digital agency with deep WordPress expertise (and some WP core committers), we developed a fully Dockerized implementation of WordPress that makes deploying and scaling WordPress on any compatible infrastructure a snap. Using the Autopilot Pattern and ContainerPilot, all the components automatically configure themselves on deploy and reconfigure themselves as you scale up and down.

The automated operation of the Autopilot Pattern makes running applications easy. When we demonstrated that ease of operation with a Node.js app backed by Couchbase that automatically configures itself on deploy and as you scale the components, many pressed us with the challenge that it was only possible because we were using modern applications. We took up that challenge when we Dockerized MySQL with the Autopilot Pattern and now again with WordPress.

In addition to the WordPress container, a complete site includes the following containers (all containers are launched automatically using Docker Compose):

  • MySQL: we're using the Autopilot Pattern implementation of MySQL for automatic backups and self-clustering so that we can deploy and scale easily
  • Memcached: improves performance by keeping frequently accessed data in memory so WordPress doesn't have to query the database for every request
  • Nginx: the front-end load balancer for the WordPress environment; passes traffic from users to the WordPress containers on the back-end
  • NFS: stores user uploaded files so these files can be shared between many WordPress containers
  • Consul: used to coordinate the containers
Autopilot Pattern WordPress

You can run multiple instances of most containers to scale for any amount of traffic. The MySQL containers will automatically configure as a cluster with a single primary and multiple replicas, and the WordPress image includes HyperDB to best utilize the MySQL cluster. Everything is automatically configured when you launch the containers, and reconfigured as you scale (or if a container fails), so running a scalable WordPress site is no more complex than running without the scaling features.

Basic setup

The images will run anywhere you can run Docker, but you can run them on Triton without having to setup and manage Docker hosts. Here's how to get started:

Hello world

The full details on the configuration options are in Github.


Extra: remote management with WordPress CLI

The WordPress image includes WP-CLI. Using that in combination with docker exec makes remote management especially easy. In the following examples, wp_wordpress_1 is the name of a running WordPress container in this project.

Set the display name of the admin user (user ID 1):

docker exec wp_wordpress_1 wp --allow-root user update 1 --display_name=''

On a Mac, this will open a web browser with the front page of the web site:

open $(docker exec wp_wordpress_1 wp --allow-root option get home)

If you imported the sample content, this command will delete the sticky post at the top of the site:

docker exec wp_wordpress_1 wp --allow-root post delete 1241

Inserting posts is easy too. In this example, sample-post.html is a file on my laptop with the content of the post I want to publish:

docker exec wp_wordpress_1 wp --allow-root post create \
    --post_content="$(cat sample-post.html)" \
    --post_title='' \
    --post_status='publish' \