Fix: Environment variables can be duplicated on run by simone-panico · Pull Request #1218 · apple/container

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