Skip to content

[BUG] [REGRESSION] Local .env interferes with explicit project selection #14587

Backlog

Description

@tralafiti

Description

Since upgrading to Docker Compose v5.8.1, restarting an existing Compose project by its project name no longer works reliably when executed from a directory belonging to an unrelated Compose project containing a .env file.

Previously, docker compose --project-name <project> restart could be used to manage existing Compose projects independently of the current working directory.

With v5.8.1, the command silently completes without restarting any containers.

Disabling automatic .env loading using COMPOSE_DISABLE_ENV_FILE=1 restores the previous behavior.

Steps To Reproduce

  1. Create a directory first containing the following compose.yaml:
services:
  first:
    image: alpine:latest
    command: sleep infinity
  1. Start the project from within that directory:
docker compose -p first up -d
  1. Create a separate directory second containing the following compose.yaml:
services:
  second:
    image: alpine:latest
    command: sleep infinity
  1. Create a .env file in the second directory:
COMPOSE_FILE=compose.yaml
  1. From within the second directory, execute:
docker compose -p first restart

Expected Behavior

The existing project first is restarted, regardless of the current working directory and the presence of unrelated local configuration files.

Actual Behavior

The command silently completes without restarting the container.

Removing the unrelated .env file or disabling automatic .env loading restores the expected behavior:

COMPOSE_DISABLE_ENV_FILE=1 docker compose -p first restart

Compose Version

Docker Compose version v5.8.1

Docker Environment


Anything else?

This regression appears to be related to #14151 and the changes introduced to project resolution and the handling of COMPOSE_FILE.

While treating COMPOSE_FILE as equivalent to --file is understandable when explicitly provided by the caller, treating a variable from an automatically discovered .env file as an explicit request to load a Compose model is problematic.

It makes project-name-based operations dependent on unrelated local configuration and breaks the established workflow of managing existing projects independently of their configuration files and working directories.

I would suggest distinguishing between:

  • An explicitly provided --file argument.
  • An explicitly exported COMPOSE_FILE environment variable.
  • A COMPOSE_FILE variable originating from an implicitly loaded .env file.

An implicitly discovered configuration should not change the semantics of an explicit project-name-based operation.

Activity

  1. changed the title [-][BUG] [REGRESSION] Unrelated local .env file causes docker compose --project-name restart to silently do nothing[/-] [+][BUG] [REGRESSION] Local .env interferes with explicit project selection[/+] on Dec 4, 2026
  2. Anurag1428 commented on Dec 4, 2026

    @Anurag1428

    Hi, I'd like to work on this. My plan: only treat COMPOSE_FILE as an explicit file when it comes from the real environment or --file, not from a local .env, and add an e2e regression test. Could I be assigned?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions