How to run a dockertools built image with virtualisation.oci-containers.containers?

Hi there!

I am converting a Docker compose file to a systemd service. The images are also built in the compose file itself.
I used compose2nix which is a great start in general. It converts the whole orchestration into systemd units. But it does not include the Dockerfiles for image builds.

I would ideally use pkgs.dockerTools.buildImage in my system nix configuration to build the image and then run it with virtualisation.oci-containers.containers. But I don’t know how to mix them.

I am using flakes but I would like to have everything of that service in my system configuration.
Any ideas?

Hi,
coincidentally I was asking a different but similar question about dockerTools. My setup described in this comment may help you.

You can assign directly

nixosConfigurations."mySystem" = nixpkgs.lib.nixosSystem {
      system = system;
      modules = [
        ...
        {
          virtualisation.docker.enable = true;
          virtualisation.oci-containers.containers."buildResult".imageFile = (pkgs.dockerTools.buildImage { ... });
        }
      ];
    };

See the example field in the nixos options. In my post I wasn’t able to finish the setup due different error so this explanation isn’t tested but I believe it should be good.

I did not think this way and did not look after this possibility to mention the imageFile.
Perfect exactly what I wanted. Thx.

1 Like