dockerTools.buildImage去掉fromImage图片的环境变量,如何保留Env?
dockerTools.buildImage removes environment variables of fromImage image, how to preserve Env?
我希望在使用 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 月以来在 Nixpkgs master
和 nixos-unstable
上的 supported,并将成为 nixos-20.09
的一部分
旧版本需要在更新父级时手动将 config.Env
参数设置为 buildImage
。现在这是自动的。
我希望在使用 dockerTools.buildImage
$ 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 月以来在 Nixpkgs master
和 nixos-unstable
上的 supported,并将成为 nixos-20.09
旧版本需要在更新父级时手动将 config.Env
参数设置为 buildImage
。现在这是自动的。