ARG
The Dockerfile instruction that declares a variable you can set at build time with --build-arg.
Values can be read back from image history, so they must never hold secrets.
In more detail
ARG values exist only while building, not in the running container, though they can appear in image history. Never pass secrets through ARG; use a build secret instead. An ARG declared before FROM can choose the base image version.
Example
ARG PYTHON_VERSION=3.12
FROM python:${PYTHON_VERSION}-alpineRelated terms
- ENV — The Dockerfile instruction that sets an environment variable in the image, visible during the build and in every container.
- build secret — A password or token given to one build step without being saved in any image layer.
- environment variable — A named setting such as PORT=8000 that a program reads from its surroundings when it starts.
Taught in
- Secrets In Use: Leaks Through Env, Specs And Images — Certified Kubernetes Security Specialist (CKS) Exam Prep
- Minimal Base Images: Less To Attack — Certified Kubernetes Security Specialist (CKS) Exam Prep
- FROM, WORKDIR, COPY And ADD — Docker Architecture & Production Containers
- RUN, SHELL And Efficient Layer Caching — Docker Architecture & Production Containers
- ARG, ENV, LABEL, EXPOSE And VOLUME — Docker Architecture & Production Containers
- CMD, ENTRYPOINT, USER And Process Signals — Docker Architecture & Production Containers
- Multi Stage Builds, Targets And Build Secrets — Docker Architecture & Production Containers
- Authenticate, Tag, Push And Pull From A Registry — Docker Architecture & Production Containers
- Scan, Patch And Inspect The Software Supply Chain — Docker Architecture & Production Containers
- Environment, Secret Files And Runtime Restrictions — Docker Architecture & Production Containers
- Build, Test And Promote The Same Image In CI — Docker Architecture & Production Containers