Skip to content

ENV documentation suggests misleading alternative #19902

Open
@rhcarvalho

Description

@rhcarvalho

Is this a docs issue?

  • My issue is about the documentation content or website

Type of issue

Information is incorrect

Description

In the documentation for the ENV instruction, there is an example that reads:

If an environment variable is only needed during build, and not in the final image, consider setting a value for a single command instead:

RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y ...

I think that suggestion is misleading, as IIUC DEBIAN_FRONTEND is only defined for the first command apt-get update and not for the apt-get install step. It is therefore not equivalent to the examples that use ENV or ARG.


Example demonstrating the problem:

$ FOO=bar printenv FOO PATH && echo 123 && printenv FOO PATH
bar
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
123
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

In the above example, FOO is defined only in the first call to printenv.

Location

https://docs.docker.com/reference/dockerfile/

Suggestion

Perhaps the most obvious solution is to repeat DEBIAN_FRONTEND:

RUN DEBIAN_FRONTEND=noninteractive apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y ...

For this particular use case in which the environment variable needs to be available to multiple commands but not be persistent in the final image, I'd emphasize the use of ARG instead, as it is less error-prone.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions