简体   繁体   English

可以将env变量从docker-compose.yml传递到dockerfile吗?

[英]Possible to pass env variable from docker-compose.yml to dockerfile?

Is it possible to pass an env from an docker-compose.yml file to dockerfile. 是否可以将env从docker-compose.yml文件传递到dockerfile。

I have inside the dockerfile like this: 我在dockerfile中有这样的内容:

RUN $(npm bin)/ng build --prod --env=prod

But what I want is when the docker-compose.yml has a build_env that is: 但是我想要的是docker-compose.yml具有build_env时:

environment:
            BUILD_ENV: 'test'

Then I want the docker 然后我要码头工人

RUN $(npm bin)/ng build --prod --env=test

How do I achieve something like this? 我如何实现这样的目标? Or are there any other better solutions to do this? 还是有其他更好的解决方案来做到这一点?

You can review this documentation: 您可以查看以下文档:

https://docs.docker.com/compose/compose-file/#args https://docs.docker.com/compose/compose-file/#args

build:
  context: .
  args:
    - buildno=1
    - password=secret
    - buildenv=prod

- --

ARG buildno
ARG password
ARG buildenv

RUN echo "Build number: $buildno"
RUN script-requiring-password.sh "$password"
RUN $(npm bin)/ng build --prod --env="$buildenv"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM