gpt4 book ai didi

docker - Dockerfile:设置了$ HOME,但是在使用它定义其他环境变量时变为空白

转载 作者:行者123 更新时间:2023-12-02 20:42:31 25 4
gpt4 key购买 nike

我有一个简单的Dockerfile看起来像这样:

FROM alpine:3

RUN echo "$HOME" # Prints '/root'
ENV OTHER_HOME="$HOME"
RUN echo "$OTHER_HOME" # Prints nothing!

RUN echo "$PATH" # Prints '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
ENV OTHER_PATH="$PATH"
RUN echo "$OTHER_PATH" # Prints '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'

我这样构建的:
docker build . --no-cache

输出令人困惑。 $OTHER_PATH将按预期方式打印,但是 $OTHER_HOME为空白。谁能解释这种行为?
% docker build . --no-cache
Sending build context to Docker daemon 335.4kB
Step 1/7 : FROM alpine:3 AS build-stage
---> e7d92cdc71fe
Step 2/7 : RUN echo "$HOME"
---> Running in f9cd2769cd78
/root
Removing intermediate container f9cd2769cd78
---> d13f007a1fdf
Step 3/7 : ENV OTHER_HOME="$HOME"
---> Running in 7493ca43f9f3
Removing intermediate container 7493ca43f9f3
---> 2d6acfe45228
Step 4/7 : RUN echo "$OTHER_HOME"
---> Running in fb960138f43e

Removing intermediate container fb960138f43e
---> caa9719aeee5
Step 5/7 : RUN echo "$PATH"
---> Running in fe1eacf50d30
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container fe1eacf50d30
---> 17267879b82e
Step 6/7 : ENV OTHER_PATH="$PATH"
---> Running in 9dd894199ea4
Removing intermediate container 9dd894199ea4
---> fa43f399604f
Step 7/7 : RUN echo "$OTHER_PATH"
---> Running in 89d67d8b6cfe
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 89d67d8b6cfe
---> 440133fc0052
Successfully built 440133fc0052

更新:陌生人仍然,如果我手动分配 $HOME,该值以后可用!
FROM alpine:3

ENV HOME='/root'
RUN echo "$HOME"
ENV OTHER_HOME="$HOME"
RUN echo "$OTHER_HOME"

该Dockerfile结果为:
% docker build . --no-cache
Sending build context to Docker daemon 335.4kB
Step 1/8 : FROM alpine:3 AS build-stage
---> e7d92cdc71fe
Step 2/8 : ENV HOME='/root'
---> Running in 4cb8a8e45b18
Removing intermediate container 4cb8a8e45b18
---> 40d0156fe68b
Step 3/8 : RUN echo "$HOME"
---> Running in 051cf7d138fb
/root
Removing intermediate container 051cf7d138fb
---> dc34c6859bcd
Step 4/8 : ENV OTHER_HOME="$HOME"
---> Running in 01dcc2788761
Removing intermediate container 01dcc2788761
---> 540ca4e9225a
Step 5/8 : RUN echo "$OTHER_HOME"
---> Running in 4e0d31d1f847
/root

最佳答案

您只能解决该问题,因为这是GitHub上的一个已报告的错误:

https://github.com/moby/moby/issues/28971

因此,您的问题没有“真正的”答案。

关于docker - Dockerfile:设置了$ HOME,但是在使用它定义其他环境变量时变为空白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60839369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com