使用 Nix dockerTools.buildImage 构建 docker 镜像 - 构建脚本中无法访问互联网?

使用 Nix dockerTools.buildImage 构建 docker 镜像 - 构建脚本中无法访问互联网?

我正在尝试构建一个简单的 docker 映像,如此处所述http://lethalman.blogspot.com/2016/04/cheap-docker-images-with-nix_15.html,但构建步骤中似乎没有网络/互联网访问。这是一个限制吗?有解决方法吗?

{ pkgs ? import <nixpkgs> {} }:

with pkgs;
let
  entrypoint = writeScript "entrypoint.sh" ''
    #!${stdenv.shell}
    set -e
    exec "$@"
  '';
in
dockerTools.buildImage {
  name = "test";
  runAsRoot = ''
    #!${stdenv.shell}
    ${dockerTools.shadowSetup}
    curl google.com
  '';

  contents = [ busybox bash curl ];

  config = {
    Cmd = [ "bash" ];
    Entrypoint = [ entrypoint ];
    #ExposedPorts = {
      #"6379/tcp" = {};
    #};
    WorkingDir = "/data";
    #Volumes = {
      #"/data" = {};
    #};
  };
}

卷曲失败并显示curl: (6) Could not resolve host: google.com.这在我使用 IP 代替时也不起作用(以避免 DNS)。完整输出:

nix build --no-substitute
builder for '/nix/store/6md5l4lhk4kb5i8b3sp7w3q5v1nd83m2-docker-layer-test.drv' failed with exit code 6; last 10 log lines:
  Writing superblocks and filesystem accounting information: done

  Executing pre-mount steps...
  Adding contents...
  Adding /nix/store/xhwhakb1zcf5wl2a8575gcrnmbbqihm2-busybox-1.30.1...
  Adding /nix/store/rm1hz1lybxangc8sdl7xvzs5dcvigvf7-bash-4.4-p23...
  Adding /nix/store/a7i4hha4gh7fsbw7bfz51l2dkhgvb59a-curl-7.65.3-bin...
  Executing post-mount steps...
  curl: (6) Could not resolve host: google.com
  [    3.476402] reboot: Power down
cannot build derivation '/nix/store/k4dz6c5xv1p430wai75yigmmw8yn9kzy-docker-layer-test.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/pk4s3nzdv3kd2gxfqr72bimvvam7h469-docker-image-test.tar.gz.drv': 1 dependencies couldn't be built
[1 built (1 failed)]
error: build of '/nix/store/pk4s3nzdv3kd2gxfqr72bimvvam7h469-docker-image-test.tar.gz.drv' failed

相关内容