Skip to content

[BUG] env_file is not loaded in docker compose (v2.34.0) for services with profiles #12644

@codingjerk

Description

@codingjerk

Description

In Docker Compose version 2.34.0, environment variables defined in an env_file are no longer loaded when running a service using docker compose run <service name>, specifically for services that have profiles:, if profile is not enabled explicitly via COMPOSE_PROFILES or --profile. In version 2.33.1, the variables were correctly loaded.

Steps to reproduce

  1. Create a docker-compose.yaml file:

    services:
      service-with-profile:
        profiles: [ test-profile ]
        env_file: .env
        command: bash -c "env | grep TEST_VAR"
        image: ubuntu:24.04
  2. Create a .env file:

    TEST_VAR_1=1
    TEST_VAR_2=2
    
  3. Run the service using docker compose run:

    docker compose run --rm service-with-profile

Expected Behavior (Docker Compose v2.33.1 or if COMPOSE_PROFILES / --profile is provided):

TEST_VAR_2=2
TEST_VAR_1=1

Actual Behavior (Docker Compose v2.34.0):

(no output, environment variables are missing)

System Information

$ docker version
Client:
 Version:           28.0.1
 API version:       1.48
 Go version:        go1.24.1
 Git commit:        068a01ea94
 Built:             Thu Mar  6 19:09:48 2025
 OS/Arch:           linux/amd64
 Context:           default

Server:
 Engine:
  Version:          28.0.1
  API version:      1.48 (minimum version 1.24)
  Go version:       go1.24.1
  Git commit:       bbd0a17ccc
  Built:            Thu Mar  6 19:09:48 2025
  OS/Arch:          linux/amd64
  Experimental:     true
 containerd:
  Version:          v2.0.3
  GitCommit:        06b99ca80cdbfbc6cc8bd567021738c9af2b36ce.m
 runc:
  Version:          1.2.5
  GitCommit:        
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
$ docker compose version  # version with the issue          
Docker Compose version 2.34.0
$ docker compose version  # working version          
Docker Compose version 2.33.1

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