How to create a docker image based on another image with dockerTools?

I want to achieve this with nix:

FROM oryd/kratos:latest
COPY contrib/quickstart/kratos/email-password/kratos.yml /home/ory

Which I think I should be first using pkgs.dockerTools.pullImage and then pkgs.dockerTools.buildImage, but how can I use the pulled image in buildImage? Should I just redirect it to $out, just like building an derivation?

This is the snippet I have right now. How can I do that?

      defaultPackage.x86_64-linux = pkgs.dockerTools.pullImage {
        name = "oryd/kratos";
        imageDigest = "sha256:11a8241b380830bf2254a8563a5f84fb4bbee9f40e869ff3a17bba3b4ac835a4";
      };

buildImage has fromImage parameter:

pkgs.dockerTools.buildImage {
  fromImage = pkgs.dockerTools.pullImage {
    name = "oryd/kratos";
    imageDigest = "sha256:11a8241b380830bf2254a8563a5f84fb4bbee9f40e869ff3a17bba3b4ac835a4";
  };
  # rest ...
}

See pkgs/build-support/docker/examples.nix.

2 Likes