ARG
What is ARG?
ARG: A build-time variable, passed with --build-arg. Available only during the build, not in the running container. ARG defines a variable that exists only while a Docker image is being built. You pass a value with docker build --build-arg VERSION=1.4, and steps in the Dockerfile can use it. It is handy for choosing a base image version, a package version or a build mode without editing the Dockerfile. Each value becomes part of the image's build history.
Frequently asked questions about ARG
What should you keep in mind with ARG?
That is also why ARG is the wrong place for secrets. Values can be read later with docker history, so a password or API token passed this way ends up readable by anyone who has the image. Use Docker's build secrets (RUN --mount=type=secret) instead. And remember that ARG values are gone at runtime. For settings the running container needs, use ENV or, better, environment variables set when the container starts.
What does an example of ARG look like?
ARG VERSION=1.0 RUN echo "building $VERSION" At a glance
| Category | Docker |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |