← All notes

Docker build variables: ARG and ENV in a Dockerfile

Answer: Build arguments and environment variables both parameterize a Docker build, but they are not a safe way to pass secrets, and they serve different roles.

What they share

In Docker Build, ARG and ENV both pass information into the build so you can parameterize it.

Do not use build arguments or environment variables for secrets, because they're exposed in the final image.

Use secret mounts or SSH mounts when you need to expose secrets securely.

Both forms are declared in the Dockerfile and can be set with flags on docker build.

How ARG and ENV differ

Build arguments are variables for the Dockerfile itself and parameterize instruction values, such as a dependency version.

Build arguments have no effect on the build unless used in an instruction.

Those values are not present in containers from the image unless the Dockerfile passes them through, but they may remain in image metadata, provenance attestations, and image history.

Environment variables are passed into the build execution environment and persist in containers created from the image.

You cannot override or set an environment variable at build-time; the values must be declared in the Dockerfile.

You can combine the two so an environment variable can still be configured at build-time.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Build arguments and environment variables; Docker, Inc., Build arguments and environment variables (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Docker, Inc., Build arguments and environment variables; Docker, Inc., Build arguments and environment variables (source). Apache-2.0 (https://raw.githubusercontent.com/docker/docs/main/LICENSE). Copyright Docker, Inc.

Cite this

Permanent ID: iil:note:h99qzhew

iinventedlight. 2026. "Docker build variables: ARG and ENV in a Dockerfile." iinventedlight Library, iil:note:h99qzhew, version of 2026-11-26. https://iinventedlight.com/library/notes/docker-build-variables/. License: CC-BY-4.0.

@misc{iil_note_h99qzhew,
  author = {{iinventedlight}},
  title = {{Docker build variables: ARG and ENV in a Dockerfile}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-26},
  url = {https://iinventedlight.com/library/notes/docker-build-variables/},
  note = {Permanent ID iil:note:h99qzhew. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/docker-build-variables.md.