我希望在使用dockerTools.buildImage时保留this variables

$ docker run -it lnl7/nix:latest env
PATH=/root/.nix-profile/bin:/run/current-system/sw/bin
HOSTNAME=52be36e10f96
TERM=xterm
MANPATH=/root/.nix-profile/share/man:/run/current-system/sw/share/man
NIX_PATH=nixpkgs=/nix/store/d7r0qlms9w7k0m5kmvinp52abxbncafv-nixpkgs-unstable-2018-01-13
GIT_SSL_CAINFO=/nix/store/dblcx21khkizv3h9n0haqbkmzig3n3wd-nss-cacert-3.33/etc/ssl/certs/ca-bundle.crt
SSL_CERT_FILE=/nix/store/dblcx21khkizv3h9n0haqbkmzig3n3wd-nss-cacert-3.33/etc/ssl/certs/ca-bundle.crt
HOME=/root

但是用这个
$ cat runner/nixops_runner.nix
{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
  workdir = "/app";

  sshConfig = writeText "ssh_config" ''
    Host *
    StrictHostKeyChecking=no
    UserKnownHostsFile /dev/null
    IdentityFile /ssh/id_rsa
  '';

  nixFromDockerHub = dockerTools.pullImage {
    imageName = "lnl7/nix";
    imageTag = "latest";

    # this hash will need change if the tag is updated at docker hub
    sha256 = "031xba6yi72v87v560wqbcsi80hqbwx498qz5b5jxigj36yb3k36";
  };
in

dockerTools.buildImage {
  name = "nixops_runner";

  fromImage = nixFromDockerHub;
}

我明白了
$ docker load --input $(nix-build runner/nixops_runner.nix --no-out-link) && docker run -it nixops_runner env
Loaded image: nixops_runner:latest
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
HOSTNAME=9d673e788746
TERM=xterm
HOME=/root

如何保存图像的环境变量?

最佳答案

自2020年5月起,这是supported,位于Nixpkgs masternixos-unstable上,并将成为nixos-20.09的一部分
较旧的版本需要在更新父级时手动将config.Env参数设置为buildImage。现在这是自动的。

关于docker - dockerTools.buildImage从fromImage图像中删除环境变量,如何保存Env?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49321680/

10-15 17:09