Deploying Wordpress Using nix-docker

Yesterday I wrote about nix-docker, a way to use Nix to provision Docker images in a nice way. Today I spent a little bit of time on a sample nix-docker configuration to deploy Wordpress to a Docker container to demonstrate that nix-docker is not just a toy, but can be used to deploy a “real” complex-ish system implementing best practices like storing all state (mysql data, uploads, logs) that needs to persist between container restarts in a volume.

The result can be found here. It’s ~130 lines long, but quite a bit of that is comments. It implements the following:

That’s it!

The result is a container that stores all important data in a volume, which you can mount from the host machine for easy back-up. To use:

# nix-docker -b -t wordpress-app wordpress.nix
# mkdir -p /data
# docker run -v /data:/data -p 80:80 -t -i wordpress-app

And voila!

wordpress screenshot