beginners/dockerfile/arg.md
The ARG directive in Dockerfile defines the parameter name and defines its default value. This default value can be overridden by the --build-arg <parameter name>=<value> in the build command docker build.
`ARG <parameter name>[=<default>]`
The build parameters have the same effect as ENV, which is to set the environment variables. The difference is that the environment variables of the build environment set by ARG will not exist in the future when the container is running. But don't use ARG to save passwords and the like, because docker history can still see all the values.
We are writing a Dockerfile which echo "Welcome $WELCOME_USER, to Docker World!" where default argument value for <b>WELCOME_USER</b> as <b>Collabnix</b>.
FROM alpine:3.9.3
LABEL maintainer="Collabnix"
#Setting a default value to Argument WELCOME_USER
ARG WELCOME_USER=Collabnix
RUN echo "Welcome $WELCOME_USER, to Docker World!" > message.txt
CMD cat message.txt
$ docker image build -t arg:v1 .
$ docker run arg:v1
Welcome Collabnix, to Docker World!
$ docker image build -t arg:v2 --build-arg WELCOME_USER=Savio .
$ docker run arg:v2
Welcome Savio, to Docker World!
<b>NOTE:</b> ARG is the only one instruction which can come before FROM instruction, but then arg value can be used only by FROM.
Next >> Lab #9: ENV instruction