---
source: https://iinventedlight.com/library/notes/docker-build-variables.md
title: "Docker build variables: ARG and ENV in a Dockerfile"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "Apache License 2.0 (Docker, Inc.); Apache License 2.0 (Docker, Inc.); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-26
status: published
approved_by: "Cole Withington, 2026-11-27 14:30 PT: \"Yes, publish all of that now\""
checked_on: 2026-11-26
as_of: 2026-11-26
confidence: medium
untested: "Not reproduced (2026-11-26). Official docs and source files were read; no test suite, server, or API call was run for this note."
category: coding-references
topic_area: "code-devops: docker-build-variables"
tags: [docker, build, arg, env, secrets]
client: Librarian
sources:
  - id: S1
    title: "Build arguments and environment variables"
    publisher: Docker, Inc.
    url: https://docs.docker.com/build/building/variables/
    accessed: 2026-11-26
    license: "Apache License 2.0"
  - id: S2
    title: "Build arguments and environment variables (source)"
    publisher: Docker, Inc.
    url: https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/building/variables.md
    accessed: 2026-11-26
    license: "Apache License 2.0"
---
# 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

- [docker-arg-and-env](https://iinventedlight.com/library/notes/docker-arg-and-env/)
- [docker-build-secrets](https://iinventedlight.com/library/notes/docker-build-secrets/)
- [docker-build-context](https://iinventedlight.com/library/notes/docker-build-context/)

## Claims

- id: C1
  claim: Build arguments and environment variables are inappropriate for passing secrets because they are exposed in the final image.
  source: S1
  evidence: "inappropriate for passing secrets to your build, because they're exposed in the final image"

- id: C2
  claim: Build arguments are variables for the Dockerfile itself.
  source: S1
  evidence: "Build arguments are variables for the Dockerfile itself"

- id: C3
  claim: Environment variables persist in containers and cannot be set at build-time except through the Dockerfile.
  source: S2
  evidence: "You can't override or set an environment variable at build-time"

## Sources

- [S1] Build arguments and environment variables. Docker, Inc.. https://docs.docker.com/build/building/variables/ . License: Apache License 2.0. Accessed 2026-11-26.

- [S2] Build arguments and environment variables (source). Docker, Inc.. https://raw.githubusercontent.com/docker/docs/main/content/manuals/build/building/variables.md . License: Apache License 2.0. Accessed 2026-11-26.

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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
