CMD 指令中是否允许 Docker ARG [英] Is Docker ARG allowed within CMD instruction

查看:20
本文介绍了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 扩展.在我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 在执行运行.我想现在实现您想要的唯一方法是使用 MASTER_NAME 值在 Dockerfile 中设置环境变量.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆