Globally scoped predefined platform ARG’s in Docker BuildKit

Sujay Pillai
2 min readJan 2, 2019

--

ARG a.k.a “build-time variable” can be used to pass a variable to builder with the docker build command using --build-arg <varname>=<value> flag.

With the new engine 18.09 Docker supports a new backend BuildKit for executing your builds. You may switch to this backend by setting the below environment variable on your CLI -

export DOCKER_BUILDKIT=1

With this new backend Docker predefines a set of ARG variables with the information pertaining to the platform of the node performing the build (build platform) and the resulting image (target platform)

The following ARG variables are set automatically:

These arguments are defined in the global scope so are not automatically available inside build stages or for your RUN commands. To expose one of these arguments inside the build stage redefine it without value as shown in below example:

Consider the below Dockerfile where we have all the above predefined ARG’s redefined

I carried out this build on a RaspberryPi to show all the values of above ARG’s

Read more about this here from Docker Documentation.

--

--