Best practices for customizing containers with docker-compose?

Hi all,

As I continue my journey to understanding how to deploy container applications at scale… I’m trying to build the most simple non-trivial Wordpress deployment in containers. My end-goal for this step (lots more to do!) is this:

  1. nginx serving as a reverse proxy cache for the application, caching static elements
  2. One Apache/PHP node running WordPress with WP Super Cache pre-installed and enabled
  3. One memcached node providing an object cache for WordPress
  4. A MySQL Server node for data persistence
  5. “Decent” hygiene: all modified files stored in version control, secrets provided through secret files rather than environment variables/hard coded, and daily database back-ups

I’d love to automate everything, including instance provisioning, various firewall and permissions settings I have come across, and to have a decent monitoring framework around the instance - but that’s all later. Right now, my main question is: what’s the best practice way for me to manage adding a plugin to WordPress? Should I build a custom contaner “FROM wordpress” that installs and enables the plugin? Or should I add a build step to my docker-compose.yml? And if so, how do you do that? I have not done that before. Is there another way? I have the WordPress directory in a volume mounted on the host, so I could wget and uncompress the zip file for the plug-in, but (if I understand correctly) that won’t survive the first time I upgrade WordPress, which isn’t ideal.

Thanks for the suggestions!

1 Like

I’ve landed on wp-cli as one option - I can install and enable plugins, change config options, etc - all from scripts on the command line. Still working out how to make it work with the tools I’m using but anyway…

1 Like

Sharing some of my learnings:

  1. Installing a WordPress plugin from the admin panel downloads the distribution (a .zip file), and uncompresses it in wp-content/plugins
  2. To enable the plugin, an “activation” hook function is registered when the plugin is installed. In the case of WP Super Cache, that function is called wpsupercache_activate
  3. The activation hook can do complex stuff - the WP Super Cache activation plug-in defines two new options in the wp-config.php file: WP_CACHE (a boolean, to indicate that the plugin is enabled) and WPCACHEHOME (the path to the wp-super-cache directory)

So it is conceivable to unzip the plug-in directly into a shared volume containing the Wordpress files, and modify the config file afterwards. But frankly, this seems very “un-Docker-like”.

The alternative is to deploy wp-cli in a container with the same Wordpress shared volume, and install the plugin with wp plugin install --activate wp-super-cache.

And incidentally, wp-super-cache does not do an object cache as far as I can tell. You need another plugin to add the ability to use memcached as an object cache.

1 Like