CMD指令中是否允许Docker ARG [英] Is Docker ARG allowed within CMD instruction
本文介绍了CMD指令中是否允许Docker ARG的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Dockerfile,在 CMD
指令中使用了 ARG
:
I have a Dockerfile where an ARG
is used in the CMD
instruction:
ARG MASTER_NAME
CMD spark-submit --deploy-mode client --master ${MASTER_URL}
arg通过docker-compose传递:
The arg is passed via docker-compose:
spark:
build:
context: spark
args:
- MASTER_URL=spark://master:7077
但是, ARG
似乎没有为 CMD $扩展c $ c>。在我
docker-compose up
之后。
However, the ARG
does not seem to get expanded for CMD
. After I docker-compose up
.
这里是检查显示的内容:
Here's what inspect shows:
docker inspect -f "{{.Name}} {{.Config.Cmd}}" $(docker ps -a -q)
/spark {[/bin/sh -c spark-submit --deploy-mode client --master ${MASTER_URL}]}
推荐答案
问题在于 args
仅可在构建时使用,而 CMD
在运行时执行。我想现在唯一实现目标的方法是在Dockerfile中使用 MASTER_NAME
值设置环境变量。
The thing is that args
only can be used at build time, and the CMD
is executing at run time. I guess that the only approach now to achieve what you want is setting an environment variable in the Dockerfile with the MASTER_NAME
value.
ARG MASTER_NAME
ENV MASTER_NAME ${MASTER_NAME}
CMD spark-submit --deploy-mode client --master ${MASTER_NAME}
这篇关于CMD指令中是否允许Docker ARG的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文