In my Dockerfile, I define ARG values and use them successfully in RUN commands.
However, in my CMD the ARG value does not appear.
Dockerfile:
FROM anapsix/alpine-java:8
MAINTAINER xxx@yyy.com
ARG NAME=UNSET
CMD echo NAME is $NAME
Example:
12:29:27 ~/workspaces/k8s/docker > docker build scratch
Sending build context to Docker daemon 2.048kB
Step 1/4 : FROM anapsix/alpine-java:8
---> f68f6cb88633
Step 2/4 : MAINTAINER xxx@yyy.com
---> Using cache
---> b974feaede6a
Step 3/4 : ARG NAME=UNSET
---> Running in 0d1ebf746c33
---> c58708f2a58c
Removing intermediate container 0d1ebf746c33
Step 4/4 : CMD echo NAME is $NAME
---> Running in 52952d8c9e0d
---> be9dca528d15
Removing intermediate container 52952d8c9e0d
Successfully built be9dca528d15
12:29:33 ~/workspaces/k8s/docker > docker run be9dca528d15
NAME is
I'd expect that line to be NAME is UNSET
, or whatever value I specify (using docker build --build-arg NAME=whatever
).