The ARG instruction

The ARG instruction lets you define variables that can be passed during the Docker image build time. The Docker build subcommand supports the --build-arg flag to pass a value to the variables defined using the ARG instruction. If you specify a build argument that was not defined in your Dockerfile, the build would fail. In other words, the build argument variables must be defined in the Dockerfile to be passed during the Docker image build time.

The syntax of the ARG instruction is as follows:

ARG <variable>[=<default value>] 

Here, the code terms mean the following:

  • <variable>: This is the build argument variable
  • <default value>: This is the default value you could optionally specify to the build argument variable

Here is an example for the ARG instruction:

ARG usr 
ARG uid=1000

Here is an example of the --build-arg flag of the docker build subcommand:

$ docker build --build-arg usr=app --build-arg uid=100 . 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset