ENV在Dockerfile中的位置是否对最终结果很重要?
我的env在Dockerfile中的位置是否
ADD rootfs /
CMD ["/usr/sbin/MyApplication -V"]
ENV MY_APP_RUN_IN_TEST=true
很重要?例如,在上面的示例中,MyApplication是否可以运行并可以访问MY_APP_RUN_IN_TEST环境变量?
还是我需要在上面移动它?
Does the location of my ENV in Dockerfile:
ADD rootfs /
CMD ["/usr/sbin/MyApplication -V"]
ENV MY_APP_RUN_IN_TEST=true
matter ? For example in the above example, will MyApplication be run and have access to the MY_APP_RUN_IN_TEST environment variable ?
or do i need to move it above it ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在您的示例中,myApplication将可以访问环境变量。该顺序没关系。
我能想到的唯一方法是没有可用的env语句,即如果您拥有多阶段的Dockerfile。然后,ENV语句必须处于最后阶段才能包含在图像中。
例如,如果您有这样的dockerfile
,则环境变量将不会可用。如果Env语句移至Dockerfile的最后阶段,则可以使用。
In your example, MyApplication will have access to the environment variable. The order doesn't matter.
The only way I can think of an ENV statement not being available, is if you have a multi-stage Dockerfile. Then the ENV statement would have to be in the final stage to be included in the image.
For instance, if you have a Dockerfile like this
then the environment variable won't be available. If the ENV statement was moved to the last stage of the Dockerfile, then it would be available.