Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENV documentation suggests misleading alternative #19902

Open
1 task done
rhcarvalho opened this issue Apr 26, 2024 · 4 comments
Open
1 task done

ENV documentation suggests misleading alternative #19902

rhcarvalho opened this issue Apr 26, 2024 · 4 comments
Labels
area/build Relates to Dockerfiles or docker build command lifecycle/frozen status/triage Needs triage

Comments

@rhcarvalho
Copy link
Contributor

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.

@rhcarvalho rhcarvalho added the status/triage Needs triage label Apr 26, 2024
@dvdksn dvdksn added the area/build Relates to Dockerfiles or docker build command label Apr 26, 2024
@docker-robot
Copy link

docker-robot bot commented Jul 25, 2024

There hasn't been any activity on this issue for a long time.
If the problem is still relevant, mark the issue as fresh with a /remove-lifecycle stale comment.
If not, this issue will be closed in 14 days. This helps our maintainers focus on the active issues.

Prevent issues from auto-closing with a /lifecycle frozen comment.

/lifecycle stale

@rhcarvalho
Copy link
Contributor Author

/remove-lifecycle stale

@rhcarvalho
Copy link
Contributor Author

This hasn't been updated and is still wrong in the live documentation.

@NickeZ
Copy link

NickeZ commented Aug 23, 2024

Another solution is to export it for that shell

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Relates to Dockerfiles or docker build command lifecycle/frozen status/triage Needs triage
Projects
None yet
Development

No branches or pull requests

4 participants