Is it possible to copy content from a existing base image using dockerTools?

Hey *,

is it possible to replicate the following steps (see snippet) using dockerTools? I am in the situation where I need to use some content from another docker image that is not nixified.

FROM hapiproject/hapi:v8.0.0 AS builder

[... other build steps ...]

COPY --chown=nonroot:nonroot --from=builder /app /app

ENTRYPOINT [ ... ]

Is it possible to replicate the COPY --from=builder /app /app part using nix docker builder or how would one achieve this?

Many thanks in advance,
qitta

Yes. It’s a little awkward though, dockertools doesn’t have explicit support for copying specific subtrees around.

That said, docker images are just fancy zip files. You can use pullImage to make nix grab images from the registry (though updating can be a bit annoying), and then have nix extract the result, something like:

pkgs.stdenv.mkDerivation {
  name = "hapi-container";
  version = "8.0.0";
  src = pkgs.dockertools.pullImage { ... };
  installPhase = ''
    # Sift through the output to find the layer that contains
    # the files you want and copy them to $out/app
  '';
}

After that it’s just a matter of using that derivation in pkgs.dockertools.buildImage’s copyToRoot.

… that said, you can possibly simplify this depending on what exactly you’re trying to copy where. It’s possible you can just use fromImage and give it the pkgs.dockertools.pullImage output.

@TLATER thanks for the quick reply - I will give it a try :).