Some time back, I published an article all about using Docker to host WordPress sites. It was built around the official wordpress:4-apache image which worked very well, but was quite large (both in RAM requirements as well as container size). I became interested in trimming the container size since I do my development on a VM at home and then copy my images to testing and deployment web servers from there over a slow residential uplink.
Enter Alpine Linux.
The Alpine/FPM-based images for WordPress start around 40MB compressed instead of the 200MB that the Ubuntu/Apache images weigh in at.
Next, because the Alpine-based images expose a FastCGI interface on port 9000 instead of a webserver on port 80, we can take advantage of nginx’s fastcgi_cache interface to build a microcache to allow our WordPress sites to handle huge spikes in volume gracefully. Microcaching has been shown to allow very small servers to handle in excess of 2500 requests per second serving WordPress. Extrapolated out, this is 9M hits/day or 270 hits/month. If we serve 10 pages per visitor, that’s top-100-level traffic!
Because of that same change in exposed interfaces, we need to bring in a webserver container, bringing our docker cluster up to three containers (db, midlayer, and webserver). We can use the official nginx:alpine image for this. We’ll need some minimal customization that can be done by importing two config files using local volumes. We have no need to build and deploy a second image.
Specifying Plugin Version
As of version 2.0.1, if you would like to use a specific version of a plugin, you can specify it with an = sign. This was necessary for image-widget since the expected URL: https://downloads.wordpress.org/plugin/image-widget.zip doesn’t work. This means to include image-widget, use image-widget=4.2.2 to specify the version and make the system fetch https://downloads.wordpress.org/plugin/image-widget.4.2.2.zip instead.
Turning off Docker Cache
As of version 2.0.0, you can disable Docker’s cache during the image build by setting the environment variable NO_CACHE=true.
Putting It All Together