nix-docker is a tool by Zef Hemel that allows you to provision your Docker images using Nix. If that sounds like a good idea, head over to Zef’s blog to read his post Declaratively Provision Docker Images Using Nix. He makes a compelling case.
Over the weekend I experimented a bit with nix-docker. One thing that took me a while to figure out is that if you want to mount a data volume, the mount point must exist on the image.
Zef’s Wordpress example uses a volume mounted at /data
. It
works, because the Apache service specification takes care of creating the
directory. If you want to create the directory yourself, you can add a script
to docker.buildScripts
.
{ config, pkgs, ... }:
{
docker.volumes = [ "/data" ];
docker.buildScripts.createVolumeDirs = ''
mkdir -p /data
'';
}
This could be and should be abstracted away, but I’m very much a beginner with Nix. Or maybe nix-docker should take care of creating the directories.