加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

码头工程ENV与RUN出口

发布时间:2020-12-16 03:32:05 所属栏目:安全 来源:网络整理
导读:假设我想结合这些命令 RUN command_1ENV FOO barRUN command_2 成 RUN command_1 export FOO=bar command_2 并且想知道如果使用RUN export对ENV设置变量是等效的. 换句话说,Dockerfile中这些命令有区别吗? ENV FOO bar VS RUN export FOO=bar 最佳答案 如is

假设我想结合这些命令

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 using docker inspect,and change them using docker 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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读