6
我有一個Nix包,我想捆綁到碼頭集裝箱中。如何用nix建立碼頭集裝箱?
具體而言,我想使用Nix作爲Dockerfile
的更具表現力的替代方案,以便更快速地(非線性)構建圖像。
我發現了有關dockerTools.buildImage
的文檔,但我希望有一個最小的工作示例,並且我也想知道在Docker容器中結束了什麼。
我有一個Nix包,我想捆綁到碼頭集裝箱中。如何用nix建立碼頭集裝箱?
具體而言,我想使用Nix作爲Dockerfile
的更具表現力的替代方案,以便更快速地(非線性)構建圖像。
我發現了有關dockerTools.buildImage
的文檔,但我希望有一個最小的工作示例,並且我也想知道在Docker容器中結束了什麼。
下面的例子包(使用contents =
)的pkgs.nginx
nixpkgs封裝成泊塢窗容器:
docker load --input $(nix-build -E 'with import <nixpkgs> {}; pkgs.dockerTools.buildImage { name = "nix-htop"; contents = pkgs.htop; config = { Cmd = [ "/bin/htop" ]; }; }')
然後,您可以用
docker run -it nix-htop
容器的內容運行是相當小,單個碼頭層:
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/
只有htop及其依賴項(glibc,ncurses),我的情況下爲26 MB。