Dockerfile ARG is a build-time variable; ENV is set in the image environment
Answer: The ARG instruction defines a variable that users can pass at build time. Pass the value to docker build with the --build-arg flag. Subsequent instructions such as FROM, ENV, and WORKDIR can use ${VAR} or $VAR. Later RUN instructions also receive that ARG as a build-time environment variable.
ENV
The ENV instruction sets the environment variable <key> to the value <value>. That value is in the environment for all subsequent instructions in the build stage. The value is interpreted for other environment variables. Quote characters will be removed if they are not escaped.
See also
Claims
- id: C1 claim: The ARG instruction defines a variable users can pass at build time. source: S1 evidence: "instruction defines a variable that users can pass at build time to"
- id: C2 claim: Pass the value with docker build --build-arg. source: S1 evidence: "--build-arg <varname>=<value>"
- id: C3 claim: The ENV instruction sets the environment variable key to value. source: S2 evidence: "The
ENVinstruction sets the environment variable<key>to the value"
- id: C4 claim: ARG syntax is ARG <name>[=<default value>]. source: S2 evidence: "ARG <name>[=<default value>]"
Sources
- [S1] Dockerfile reference (ARG and ENV). Docker docs. https://docs.docker.com/reference/dockerfile/ . License: Apache-2.0. Accessed 2026-11-16.
- [S2] Dockerfile reference (docs source). docker/docs (GitHub). https://github.com/docker/docs/blob/main/_vendor/github.com/moby/buildkit/frontend/dockerfile/docs/reference.md . License: Apache-2.0. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference (ARG and ENV), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE); docker/docs (GitHub), Dockerfile reference (docs source), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE). Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker docs, Dockerfile reference (ARG and ENV), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE); docker/docs (GitHub), Dockerfile reference (docs source), Apache-2.0 (https://github.com/docker/docs/blob/main/LICENSE).
Cite this
iinventedlight. 2026. "Dockerfile ARG is a build-time variable; ENV is set in the image environment." iinventedlight Library, iil:note:5frhc5s6, version of 2026-11-16. https://iinventedlight.com/library/notes/docker-arg-and-env/. License: CC-BY-4.0.
@misc{iil_note_5frhc5s6,
author = {{iinventedlight}},
title = {{Dockerfile ARG is a build-time variable; ENV is set in the image environment}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/docker-arg-and-env/},
note = {Permanent ID iil:note:5frhc5s6. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-arg-and-env.md.