Is Docker ARG allowed within CMD instruction
DockerDocker ComposeDocker Problem Overview
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}]}
Docker Solutions
Solution 1 - Docker
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}