Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] env_file property on include top-level element is relative to current directory instead of the directory of compose.yml #11577

Closed
jcoll-busup opened this issue Mar 5, 2024 · 1 comment

Comments

@jcoll-busup
Copy link

Description

The documentation for the include top-level element states the following about the env_file property:

env_file defines an environment file(s) to use to define default values when interpolating variables in the Compose file being parsed. It defaults to .env file in the project_directory for the Compose file being parsed.

env_file can be set either to a string or a list of strings when multiple environment files need to be merged to define a project environment.

Knowing that compose will use the .env file found on the project_directory, one would expect it to do the same for the environment files defined on the include top-level element (making use of the project_directory as relative path for env_file).

Yet, in practice it only will look at the current working directory and stop there, showing an error similar to this:
Couldn't find env file: .../.env.defaults.

This makes the env_file property kind of useless, as it will break the usage of the compose config from anywhere but the project root.

I think this may be related to issues #11392 and #11405.

Steps To Reproduce

  1. Create the following project structure:
compose-example/
  - compose.yml
  - include/
    - main.yml
    - .env.main
  1. Recreate the files with the following content:
# compose.yml
include:
  - path: include/main.yml
    project_directory: ./
    env_file: include/.env.main
# include/main.yml
services:
  hello-world:
    image: ${HELLO_WORLD_IMAGE}
    network_mode: none
# include/.env.main
HELLO_WORLD_IMAGE=hello-world:latest
  1. Run the hello-world container from the project root, which should work fine:
    docker compose run hello-world

  2. Enter into a subdirectory and repeat the previous command; it will fail with a message similar to this one: "Couldn't find env file: include/.env.main"
    cd include && docker compose run hello-world

Compose Version

Docker Compose version v2.24.6

Docker Environment

Client: Docker Engine - Community
 Version:    25.0.3
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.12.1
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.24.6
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 22
  Running: 21
  Paused: 0
  Stopped: 1
 Images: 35
 Server Version: 25.0.3
 Storage Driver: btrfs
  Btrfs: 
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: active
  NodeID: ol81y1nxwbxehpwrg3y85p6sl
  Is Manager: true
  ClusterID: lnx9q652c5ilk8ezx27s5zhs3
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.1.25
  Manager Addresses:
   192.168.1.25:2377
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: ae07eda36dd25f8a1b98dfbf587313b99c0190bb
 runc version: v1.1.12-0-g51d5e94
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.5.0-21-generic
 Operating System: Ubuntu 23.10
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.54GiB
 Name: silver-wolf
 ID: 67QL:C3EK:7DPH:V6KP:3OSW:E2E7:QUMX:VWJS:4K7S:R2XC:IZY3:IPGO
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

@ndeloof
Copy link
Contributor

ndeloof commented Mar 5, 2024

already fixed by compose-spec/compose-go#593

@ndeloof ndeloof closed this as completed Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants