Repository navigation
Description
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
- Create a directory
firstcontaining the followingcompose.yaml:
services:
first:
image: alpine:latest
command: sleep infinity- Start the project from within that directory:
docker compose -p first up -d- Create a separate directory
secondcontaining the followingcompose.yaml:
services:
second:
image: alpine:latest
command: sleep infinity- Create a
.envfile in theseconddirectory:
COMPOSE_FILE=compose.yaml- From within the
seconddirectory, execute:
docker compose -p first restartExpected 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 restartCompose 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
--fileargument. - An explicitly exported
COMPOSE_FILEenvironment variable. - A
COMPOSE_FILEvariable originating from an implicitly loaded.envfile.
An implicitly discovered configuration should not change the semantics of an explicit project-name-based operation.
Activity
[-][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[/+]Anurag1428 commentedon Dec 4, 2026
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?