Running wordpress in docker

The wife now also starts a blog. Time to play: This blog here is still set up the old-fashioned way, php and mysql running on the web server. But setting up a wordpress for her gives me a welcome excuse to play with docker.

So there you go:

For the simplified creation of vhosts for docker containers I set use a trio of containers using a slightly-adapted version of this docker-compose.yml:

  • nginx as reverse-proxy
  • jwilder/docker-genfor automatic creation of v-hosts based on container environment variables: simply pass -e VIRTUAL_HOST=your.domain.com and this container adapts the vhosts config for nginx accordingly.
  • jrcs/letsencrypt-nginx-proxy-companion to also automatically fetch a letsencrypt certificate and enable ssl for the new vhost..

For the wordpress instance I run an adapted docker-compose.yml for the usual container pair of wordpress and mysql. Apart from keeping the wordpress instance in a directory volume (for easy fiddling) i added the following modification:

     environment:
       VIRTUAL_HOST: <vhost-1>.de,<vhost-2>.de...
       LETSENCRYPT_HOST: <vhost-1>.de,<vhost-2>.de...
       LETSENCRYPT_EMAIL: <letsencrypt-mail>

This enables automatic creation and sslification of the vhost in the nginx reverse proxy.

The nginx-reverse-proxy solution really makes it very convenient to just spin up a new container and immediately use it with a valid SSL certificate. Definitely worth the time for initial setup – it does not take longer than setting up SSL manually but you only have it once to get SSL for all vhosts.