Skip to content

Fix: Environment variables can be duplicated on run - #1218

Merged
katiewasnothere merged 6 commits into
apple:mainfrom
simone-panico:fix-env-duplication
Feb 21, 2026
Merged

Fix: Environment variables can be duplicated on run #1218
katiewasnothere merged 6 commits into
apple:mainfrom
simone-panico:fix-env-duplication

Conversation

@simone-panico

@simone-panicosimone-panico commented Feb 14, 2026

Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

As reported in 1212, environment variables defined in a Dockerfile (ENV) were not being overridden when passed via -e at runtime, resulting in duplicate entries in the container's environment.

Root cause:Parser.allEnv() simply merged image, env-file, and user-provided environment variables without deduplication. Since getenv() returns the first match, the image default took precedence over the user override.

Fix:allEnv() now deduplicates by key, with later sources overriding earlier ones

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@simone-panico
simone-panico marked this pull request as ready for review February 14, 2026 21:34
Comment threadSources/Services/ContainerAPIService/Client/Parser.swift Outdated
Comment threadTests/ContainerAPIClientTests/ParserTest.swift Outdated
@JaewonHur

Copy link
Copy Markdown
Contributor

@simone-panico Could you run make fmt and commit again?

@katiewasnothere
katiewasnothere merged commit c48ed09 into apple:mainFeb 21, 2026
3 checks passed
jianliang00 pushed a commit to jianliang00/container that referenced this pull request Aug 28, 2026
## Type of Change
- [x] Bug fix
- [ ] New feature - [ ] Breaking change
- [ ] Documentation update
## Motivation and Context
As reported in [1212](apple#1212),
environment variables defined in a Dockerfile (ENV) were not being
overridden when passed via -e at runtime, resulting in duplicate entries
in the container's environment.
**Root cause:** `Parser.allEnv()` simply merged image, env-file, and
user-provided environment variables without deduplication. Since
`getenv()` returns the first match, the image default took precedence
over the user override.
**Fix:** `allEnv()` now deduplicates by key, with later sources
overriding earlier ones
## Testing
- [x] Tested locally
- [x] Added/updated tests
- [ ] Added/updated docs
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@simone-panico@JaewonHur@katiewasnothere@jglogan