Skip to content

[docs-scanner] Environment variable precedence doesn't account for dual .env file scenario #25320

@github-actions

Description

@github-actions

File: content/manuals/compose/how-tos/environment-variables/envvars-precedence.md

Issue

The precedence documentation mentions "an environment file" (singular) but doesn't account for the scenario where Compose can load two .env files simultaneously - one from the working directory (PWD) and one from the project directory.

From the precedence list in envvars-precedence.md:

  1. Set with either the environment or env_file attribute but with the value interpolated from your shell or an environment file. (either your default .env file, or with the --env-file argument in the CLI).

This mentions "your default .env file" without clarifying that there can be two .env files loaded.

Meanwhile, variable-interpolation.md documents this dual-file scenario in the section "local .env file versus .env file":

When executed without an explicit --env-file flag, Compose searches for an .env file in your working directory (PWD) and loads values both for self-configuration and interpolation. If the values in this file define the COMPOSE_FILE pre-defined variable, which results in a project directory being set to another folder, Compose will load a second .env file, if present. This second .env file has a lower precedence.

And the precedence list in variable-interpolation.md explicitly shows both:

  1. If --env-file is not set, variables set by an .env file in local working directory (PWD)
  2. Variables from a file set by --env-file or an .env file in project directory

Why this matters

A reader following the precedence documentation in envvars-precedence.md would not know that Compose can load two .env files and how they interact with each other. This creates an incomplete mental model of how environment variable precedence works.

When a user encounters the dual .env file scenario (PWD vs project directory), they won't find guidance in the precedence documentation about which file takes precedence.

Suggested fix

Update the precedence documentation in envvars-precedence.md to acknowledge that there can be two .env files (PWD and project directory) and clarify their relative precedence. Either:

  1. Expand item #1 Provide instructions for stopping the nginx container #2 in the precedence list to mention both .env files and their order, or
  2. Add a note after the precedence list explaining the dual .env file scenario and linking to the detailed explanation in variable-interpolation.md

Example addition:

Note: When Compose loads an .env file from your working directory that sets COMPOSE_FILE to a different location, Compose may load a second .env file from the project directory. In this case, the working directory .env file has higher precedence than the project directory .env file. See local .env file versus project directory .env file for details.


Found by nightly documentation quality scanner

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions