dockerTools.buildImage ADD/COPY equivalent

If, for example, I have a python script that I want to copy into a docker image how would I do that with dockerTools.buildImage? I’m looking for something like ADD or COPY in a normal Dockerfile.

You’re looking for contents https://nixos.org/manual/nixpkgs/stable/#ssec-pkgs-dockerTools-buildLayeredImage

I haven’t tested this, but from the description, this should work:

buildImage {
  ...
  contents = [
    ./myscript.py
  ];
}

and then myscript.py should exist at /myscript.py within the container

EDIT:
Paths will be added to the nixstore, (e.g. /nix/store/…-myscript.py) then included as an input for the derivation
https://nixos.wiki/wiki/Nix_Expression_Language

2 Likes

I solved by creating a new directory, putting my script there, then including ./directory in contents. Thanks!

Note to anyone in the future stuck on this: it needs to be in a directory, just specifying the filename will give you errors

2 Likes