My Hugo + WordPress hybrid was starting to become difficult to maintain. I’d wanted to get a “vanilla” WordPress install up and running in Docker since I started this adventure several years ago. I had to wait for Docker technology to get a little bit more mature… I still have some serious issues, however slightly manageable.
Docker
Lets face it, Docker (or something like it) is the future of developing applications. WordPress and Docker aren’t exactly a perfect match, right out of the box. There’s some difficult problems to solve, which plugins can solve. It looks like I’ll be writing a few new plugins myself to really make it maintainable.
Docker allows easily clustering servers to work as a single unit (using Docker Swarm), it allows the developer to build something that “just works” in almost any environment.
WordPress
WordPress powers a large portion of the web. It’s the defacto publishing platform in existence. I’ve been using it since 2009, and I intend to keep using it.
The Problem
WordPress and Docker don’t do amazingly well together. Docker expects any application running in it to be completely ephemeral. This means anything you store on a disk will likely disappear at any moment (like media, plugins, and themes).
JetPack is not a fan of this. At least one of it’s features immediately vanish due to this. For example:
- Photon: If I upload something, it may or may not hit the container with the new image, causing it not to cache. When that container is destroyed, so is the content. Forever. I’m using the plugin wp-stateless to store my media in a Google Storage Bucket for now.
VaultPress also runs into an issue due to how Docker does SNAT. I’ll probably write yet another post railing Docker for not understanding how the internet works … again. That issue has been open for over six months, and it pretty much means anyone who wants to use Docker in production with any kind of logging … well, is screwed.
There’s a workaround, but the container the workaround is enabled for cannot connect to the overlay network and cannot connect to containers running on other hosts. So I don’t get the point of it at all.
My hacky solution
My solution lives in a repo called Scalable WordPress. It can bootstrap a cluster and get WP up and running in about 5 minutes. No guarantees that it works 100%. If you want to give it a shot, GitHub’s master is about 20 commits behind my local master. I’ll update it soon, after I hammer out a few generalization issues.
Basically, to get started, you’d need a Docker Swarm cluster, and the repo will walk you through bootstrapping a Galera cluster for MySQL. If you really want to do it correctly, you’d just put your MySQL data somewhere safer. Such as Amazon RDB, or Azure MySQL. I’m running on the cheap, so, I’m not doing that. I rely on VaultPress to keep my site backed up so that I can restore it (manually) if I need to.
Once the database is updated, you install themes and plugins by updating a yml file. At some point, I’ll write a plugin that will handle all this via UI. But for now, this works.
It uses traefik as a load balancer and letsencrypt. It’s pretty straightforward. You can actually see the realtime health at http://withinboredom.info:8000/dashboard/#!/health
Up Next
- Solving the SNAT problem: hoping there’s a solution I can live with…
- Writing some kind of plugin to intercept the plugin install/uninstall so I don’t have to ssh to the server to install a plugin.
- Cleaning up this blog. It doesn’t look great, but it’s fine for now. I need to create some better pictures.