【发布时间】:2020-11-08 21:14:18
【问题描述】:
短版:我需要在 Docker 映像中包含 file 实用程序。源环境和目标环境都是 NixOS。如何定义 docker 映像以便另一个可执行文件可以调用它,或者任何其他预打包的可执行文件?
更长的版本:我已经成功构建了一个 docker 镜像,我将一个预编译的可执行文件复制到适当的位置。该可执行文件现在需要调用 file 实用程序来识别各种文件的 MIME 类型,这就是我遇到的问题。
像我在shell.nix 中那样使用buildInputs 并没有达到预期的效果。有人能指出我需要的线索吗?
我的docker.nix如下:
with import <nixpkgs> {};
let
foobar_deriv = stdenv.mkDerivation rec {
name = "foobar";
builder = "${bash}/bin/bash";
args = [ ./nix-builder.sh ];
inherit coreutils openssl libyaml;
system = builtins.currentSystem;
schemapath = ../../schemas;
foobarpath = ./foobar;
buildInputs = [
pkgs.bash
pkgs.file
];
env = buildEnv {
name = name;
paths = buildInputs;
};
};
ld_path = stdenv.lib.makeLibraryPath [
pkgs.openssl
pkgs.libyaml
];
entrypoint = writeScript "entrypoint.sh" ''
#!${stdenv.shell}
export LD_LIBRARY_PATH=${ld_path}
exec $@
'';
in
pkgs.dockerTools.buildImage {
name = "myaccount/foobar";
tag = "0.3.0a11";
created = "now";
contents = foobar_deriv;
config = {
Cmd = [ "foobar" ];
Entrypoint = [ entrypoint ];
ExposedPorts = {
"4949/tcp" = {};
};
WorkingDir = "/";
};
}
【问题讨论】: