Skip to content

env_file doesn't work with profiles #4069

@deepak-endowus

Description

@deepak-endowus

Description

It seems that env_files do not get loaded when a profile is set.

Steps to reproduce the issue

Given docker-compose.yml:

services:
  app:
    profiles:
      - sg
    env_file:
      - .env.common
    image: bash
    command: >
      sh -c "echo '--- Environment Variables Inside Container ---' &&
              env | sort &&
              echo '--- End Environment Variables ---' &&
              echo 'Container paused for inspection. Use Ctrl+C to stop.' &&
              sleep 3600" 

and env.common:

TEST_ENV_INJECTION=WORKS

Describe the results you received and expected

When starting the container...

~/s/compose-env-bug ❱ nerdctl compose up --profile sg
WARN[0000] Ignoring: [Profiles]
WARN[0000] Ignoring: service app: [Profiles EnvFiles]
INFO[0000] Ensuring image bash
INFO[0000] Re-creating container compose-env-bug-app-1
INFO[0000] Attaching to logs
app-1 |--- Environment Variables Inside Container ---
app-1 |HOME=/root
app-1 |HOSTNAME=app
app-1 |PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
app-1 |PWD=/
app-1 |SHLVL=1
app-1 |_BASH_BASELINE=5.2.37
app-1 |_BASH_BASELINE_PATCH=37
app-1 |_BASH_LATEST_PATCH=37
app-1 |_BASH_VERSION=5.2.37
app-1 |--- End Environment Variables ---
app-1 |Container paused for inspection. Use Ctrl+C to stop.

The environment var TEST_ENV_INJECTION from env.common is not injected.

It works when the profiles declaration is removed from the docker-compose file.

What version of nerdctl are you using?

nerdctl version 2.0.3

Are you using a variant of nerdctl? (e.g., Rancher Desktop)

Rancher Desktop for macOS

Host information

❱ nerdctl info
Client:
Namespace: default
Debug Mode: false

Server:
Server Version: v1.7.17
Storage Driver: overlayfs
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 2
Plugins:
Log: fluentd journald json-file none syslog
Storage: native overlayfs
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.6.71-0-virt
Operating System: Alpine Linux v3.20
OSType: linux
Architecture: aarch64
CPUs: 2
Total Memory: 3.824GiB
Name: lima-rancher-desktop
ID: 603d7ff2-0c40-41f5-88fe-efb7c2b63b77

WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled

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