Skip to content

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

Closed

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

Activity

  1. codingjerk commented on Mar 18, 2025

    @codingjerk
    Author

    @ndeloof Issue was probably introduced here

  2. changed the title [-][BUG] `env_file` is Not Loaded in `docker compose` (v2.34.0) for Services with Profiles[/-] [+][BUG] `env_file` is not loaded in `docker compose` (v2.34.0) for services with profiles[/+] on Mar 18, 2025
  3. lily-controlzee commented on Mar 21, 2025

    @lily-controlzee

    thanks for reporting. I just encountered the same issue and you saved me the trouble of making a repro

  4. Aden-Q commented on Mar 25, 2025

    @Aden-Q

    The issue still exists as of v2.34.0, compose doesn't respect env_file when there's a profile section

  5. davidrunger commented on Mar 25, 2025

    @davidrunger

    The issue still exists as of v2.34.0, compose doesn't respect env_file when there's a profile section

    @Aden-Q : I believe that is expected. I think v2.34.0 is the release in which this bug was first introduced. Presumably it will be fixed in the next release.

  6. StefanWetterActiware commented on Mar 26, 2025

    @StefanWetterActiware

    Does anyone know when a release fixing this bug will be available?

  7. aukaost commented on Mar 29, 2025

    @aukaost

    Getting a release out for this issue would be most appreciated.

  8. davidrunger commented on Apr 17, 2025

    @davidrunger

    v2.35.0 is now available, which includes a fix for this bug.

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