Dockerfile `ENV` mutates system-wide `/etc/environment`
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- docker, typescript
Research direction
Start at src/spec-common/injectHeadless.ts lines 750-761 and reproduce the behavior with the provided Ubuntu Dockerfile and environment variables. Inspect how Dockerfile ENV values are written to /etc/environment, then verify that opening the container no longer persists those values system-wide while normal container execution still receives them.
Written by the indexing model from the issue text.
Description
Problem: Extremely surprising that DevContainers mutates system-wide /etc/environment at all.
This is a pretty insane architectural choice for a few reasons:
- fails rule of lease surprises
- is a breaking-change compared to other container runners, doesn't match deployment of a target container
- major security concern for per-user secrets, or build-time only secrets, getting injected into the system environment where every user (e.g. daemon web applications, databases, etc.) now potentially has these secrets in their environment
Reproduce this issue, create a Dockerfile:
FROM ubuntu:24.04
ENV DEBIAN_FRONTEND=noninteractive
# Layer 1: Locale + Timezone
RUN apt-get update && apt-get install -y --no-install-recommends \
locales tzdata \
&& sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen \
&& locale-gen \
&& ln -fs /usr/share/zoneinfo/America/Los_Angeles /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata \
&& rm -rf /var/lib/apt/lists/*
ENV LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 TZ=America/Los_Angeles
# Switch to picard user for all per-user tool installs
USER picard
WORKDIR /home/picard
# Layer: Rust (stable via rustup)
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
-y --default-toolchain stable --profile default
ENV PATH="/home/picard/.cargo/bin:$PATH"
Just opening a container using VsCode will edit the /etc/environment:
# Open a shell inside the container
docker compose exec claude-dev zsh
From the container:
cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
ANTHROPIC_API_KEY="sk-ant-your-key-here"
OPENAI_API_KEY="sk-your-key-here"
GEMINI_API_KEY="your-key-here"
PATH="/home/picard/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
DEBIAN_FRONTEND="noninteractive"
LANG="en_US.UTF-8"
LC_ALL="en_US.UTF-8"
TZ="America/Los_Angeles"
In this repro, it means that every user's Rust bin will be served from the picard user's home directory. That's just not how this should work.
I don't believe this is the intention for the ENV directive of a Dockerfile!
https://docs.docker.com/reference/dockerfile/#env
When you run docker exec, the container runtime reads the same image config and passes the ENV vars via execve to the new process, regardless of which user it runs as (--user). So every docker exec session gets them. But this is very different than injecting it into /etc/environment where the change is persisted for any user logging into the container (e.g. ssh) and not limited to docker exec.
- Dominant language
- TypeScript
- Stars
- 3k
- Forks
- 461
- Avg merge
- 13h 17m
- Merged PRs (30d)
- 6
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from devcontainers/cli
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
devcontainers/cli#1203 ·
-
Difficulty 1/5 1-3 hours Newbie friendliness 68/100
devcontainers/cli#1178 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
devcontainers/cli#1301 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 74/100
devcontainers/cli#1300 ·
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
devcontainers/cli#1298 ·
All issues in devcontainers/cli
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
copse-dev/agent-pane#2953 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Eynzof/Hermes-CN-Desktop#610 ·
-
bug clawsweeper:linked-pr-open clawsweeper:needs-live-repro clawsweeper:no-new-fix-pr impact:message-loss issue-rating: 🐚 platinum hermit P2 regression
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·