Is Docker ARG allowed within CMD instruction

2019-04-03 08:05发布

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}

The arg is passed via docker-compose:

  spark:
    build:
      context: spark
      args:
        - MASTER_URL=spark://master:7077

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}]}

1条回答
等我变得足够好
2楼-- · 2019-04-03 08:47

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}
查看更多
登录 后发表回答