假设我想结合这些命令
RUN command_1
ENV FOO bar
RUN command_2
成
RUN command_1 && export FOO=bar && command_2
并且想知道如果使用RUN export对ENV设置变量是等效的.
换句话说,Dockerfile中这些命令有区别吗?
ENV FOO bar
VS
RUN export FOO=bar
最佳答案
如issue 684所示,导出不会在图像之间持续存在. (不要忘记,每个Dockerfile指令将生成一个中间容器,提交到一个中间映像:该映像不会保留导出的值)
ENV
将:
The environment variables set using
ENV
will persist when a container is run from the resulting image.
You can view the values usingdocker inspect
,and change them usingdocker run --env
.
问题是:
RUN export PATH=$PATH:/foo/bar # from directly in builder
When I do
docker run [img] bash -c 'echo $PATH'
it never includes/foo/bar
.