Dockerfile instructions
Dockerfile ARG
Declares a build parameter, optionally with a default. Pass --build-arg NAME=value at build time. Scope starts at declaration; global pre-FROM arguments must be brought into a stage. Do not use for secrets. Record build input separately from image environment and avoid confidential arguments.
Formal Syntax & Structure
docker syntaxdocker
ARG <name>[=<default>]Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| name | string | Build parameter name. |
| default | string | Optional initial value. |
Working Example
Example Snippetdocker
FROM busybox:1.37ARG BUILD_COLOR=blueRUN printf "%s\n" "$BUILD_COLOR" > /build-color.txtENV APP_MODE=demoCMD ["sh", "-c", "cat /build-color.txt; printf \"%s\\n\" \"$APP_MODE\""]