Deploying Docker Containers with Nix
I’ve slowly been migrating my ansible-based homelab provisioning setup to NixOS. I was worried at first since I wasn’t sure how well it’d support docker and docker-compose, but it’s been almost* flawless so far. The magic lies in virtualisation.oci-containers.containers. Setup The first thing we need to do is enable an oci backend, either docker or podman. I’m used to docker so I went with the rootless version. # virtualization.nix {...}: { virtualisation = { docker.rootless.enable = true; docker.rootless.setSocketVariable = true; docker.autoPrune.enable = true; containerd.enable = true; oci-containers.backend = "docker"; # defaults to podman }; environment.sessionVariables = { DOCKER_HOST = "unix:///run/docker.sock"; # fix for rootless docker }; } [!NOTE] There is the virtualisation.docker.rootless.setSocketVariable option but it didn’t work for me, so I set DOCKER_HOST manually. ...