ScanSkill

ARG

The ARG instruction is used to define a variable that a user can pass at build-time. Users can pass variables with the docker build command using --build-arg <varname>=<value> flag. You need to define the build argument in the Dockerfile, otherwise, it will throw a warning like “[warning] One or more build-args [foo] were not consumed.”

Syntax

ARG <name>[=<default value>]

Define the default value if you want to use it when no other values are passed at build time.

Example

FROM ubuntu
ARG user1
ARG userid

USER $user1

At build time the values need to be passed:

$ docker build --build-arg user1=sahas --build-arg userid=5555 .

Also, an ARG instruction can have a default value, which will be used if no other values are passed at build-time:

FROM ubuntu
ARG user1=sagar
ARG userid=9999

USER $user1