liveBook · Manning

Arg instruction

As explained in Learn Docker in a Month of Lunches, Second Edition

An ARG instruction is a Dockerfile directive that declares a build-time argument whose value is available only while an image is being built.

Use ARG in a Dockerfile to declare build-time values. Unlike ENV, an ARG value exists only while the image is built, so containers created from the image do not receive it. section 11.3

Stamp build metadata into an image

Declare defaults, then use the arguments in labels: ARG BUILD_NUMBER=0, ARG BUILD_TAG=local, LABEL build_number=${BUILD_NUMBER}, and LABEL build_tag=${BUILD_TAG}. Override a value with docker image build --build-arg BUILD_TAG=ch11 -t numbers-api .; inspect the resulting labels with docker image inspect. section 11.3

How Learn Docker in a Month of Lunches, Second Edition covers it

How deep it goes
Defines scope, defaults, label expansion, command-line overrides, and Compose wiring, but does not detail broader Dockerfile argument rules.
Examples
Uses build numbers and tags to label a numbers API image and share metadata across Compose services.
What it assumes
Assumes basic Dockerfile and Docker Compose usage while distinguishing ARG from ENV through a concrete build workflow.
What you can do after
Operate/configure Docker builds with defaults, --build-arg overrides, Compose arguments, and inspectable image metadata.
How it connects
Connects build arguments with Dockerfile labels, environment variables, Docker Compose, CI pipelines, and image inspection.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Docker in a Month of Lunches, Second Edition. The section links point to the parts of the book it draws on.