Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions content/manuals/build/building/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,26 @@ Values for environment variables must be declared in the Dockerfile.
You can combine environment variables and build arguments to allow
environment variables to be configured at build-time.

### How substitution works

The builder interpolates `$VAR` / `${VAR}` in instructions such as
`FROM`, `COPY`, `ADD`, `ENV`, `EXPOSE`, `LABEL`, `USER`, `VOLUME`,
and `WORKDIR`.

It does not interpolate `RUN`, `CMD`, or `ENTRYPOINT`. Those get
variables from the shell (or whatever process you start) when the
instruction actually runs — `RUN` at build time, `CMD` / `ENTRYPOINT`
when the container starts. The exec form does not start a shell, so
`$HOME` stays literal unless you invoke `sh -c` yourself.

`FROM` only substitutes `ARG` values declared before that `FROM`.
An `ENV` is not visible there.

Both `ARG` and `ENV` show up in the environment of a shell-form `RUN`.
`ENV` is persisted in the image; `ARG` is not, unless you copy it into
an `ENV`. If both set the same name, later instructions see the most
recently set value.

For an example on how to use environment variables for configuring builds,
see [`ENV` usage example](#env-usage-example).

Expand Down