我有一个用例,其中我在openshift配置映射中存储两个参数,如下所示-
DT_URL="https://www.something.com"
DT_TOKEN="1234ABCD"
现在,我希望使用詹金斯在运行时获取这些值。在我的dockerfile中,我有如下参数-
ARG URL=${DT_URL}
ARG TOKEN=${DT_TOKEN}
不幸的是我没有得到任何价值。我将不胜感激任何帮助。
ARG
用于定义仅在图像构建期间有效的变量。
ENV
可用于定义在映像构建期间和容器运行期间存在的环境变量。
这里的问题是ARGs
,在使用该--build-arg
选项构建映像时,您只能通过。
但是,没有什么能阻止您在Dockerfile中将ARG
an的值分配给ENV
an。
这是一个例子:
创建一个 Dockerfile
FROM alpine
ARG MY_ARG
ENV MY_ENV=$MY_ARG
RUN echo "the env is:" $MY_ENV
RUN echo "the arg is:" $MY_ARG
构建图像:
docker build -t arg-env-example --build-arg MY_ARG=some_value .
在构建期间,ARG和ENV都被分配了some_value:
...
Step 4/5 : RUN echo "the env is:" $MY_ENV
---> Running in 9a383134c927
the env is: some_value
Removing intermediate container 9a383134c927
---> 8a2d83609296
Step 5/5 : RUN echo "the arg is:" $MY_ARG
---> Running in b881d9f4208e
the arg is: some_value
...
运行容器并检查ARG
和ENV
:
docker run -it arg-env-example sh
/ # echo $MY_ENV
some_value << this is the value that was passed at build-time to MY_ARG
/ # echo $MY_ARG
<< nothing here :)
/ #
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句