How to build a docker container with nix?

前端 未结 1 1202
情深已故
情深已故 2021-02-08 08:29

I have a Nix package I\'d like to bundle up into a docker container.

Specifically, I want to use Nix as a more expressive alternative to a Dockerfile to hav

相关标签:
1条回答
  • 2021-02-08 09:10

    The following example packages (using contents =) the pkgs.nginx nixpkgs package into a docker container:

    docker load --input $(nix-build -E 'with import <nixpkgs> {}; pkgs.dockerTools.buildImage { name = "nix-htop"; contents = pkgs.htop; config = { Cmd = [ "/bin/htop" ]; }; }')
    

    You can then run it with

    docker run -it nix-htop
    

    The contents of the container are pretty minimal, a single Docker layer:

    docker save nix-htop | tar x --to-stdout --wildcards '*/layer.tar' | tar t --exclude="*/*/*/*"
    ./
    ./bin/
    ./bin/htop
    ./share/
    ./share/applications/
    ./share/man/
    ./share/pixmaps/
    nix/
    nix/store/
    nix/store/gi5vvbjawzw1bakiksazbd50bvfmpmmc-ncurses-6.0/
    nix/store/pa5nkrpd5hg5qp1dc4gmbd2vdhn1y3x2-htop-2.0.2/
    nix/store/vn6fkjnfps37wa82ri4mwszwvnnan6sk-glibc-2.25/
    

    Only htop and its dependencies (glibc, ncurses), 26 MB on my case.

    0 讨论(0)
提交回复
热议问题