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:
- MySQL storing its data in the Docker volume
- Apache with PHP5 enabled listening on exposed port
80and storing logs in
- WordPress with an extra theme (to show how to do that), configured to store uploads in
/data/uploadsso that they, too, survive container restarts.
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