Skip to content

--env-file is ignored if YAML file is in subdirectory #8930

Description

@ilka-schulz

Description

If running a docker-compose command like

docker-compose -f subdir/foo.yml --env-file .env up -d

then docker-compose will ignore the --env-file option. However, using an absolute path, like

docker-compose -f subdir/foo.yml --env-file "$PWD/.env" up -d

then docker-compose will respect the --env-file option. This behavior is contrary to all other GNU tools which will look for .env in the current working directory.

Steps to reproduce the issue:

  1. have a YAML file in a subdirectory
  2. have an environment file in you current working directory
  3. run docker-compose with relative paths (see example in description)

Describe the results you received:
A long list of warnings about undefined variables is printed to console. It is those variables which are defined in the environment file.

Describe the results you expected:
docker-compose should just read the specified environment file.

Output of docker compose version:

docker-compose version 1.28.2, build 67630359
docker-py version: 4.4.1
CPython version: 3.7.9
OpenSSL version: OpenSSL 1.1.0l  10 Sep 2019

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  app: Docker App (Docker Inc., v0.9.1-beta3)
  buildx: Build with BuildKit (Docker Inc., v0.6.3-docker)
  scan: Docker Scan (Docker Inc., v0.9.0)

Server:
 Containers: 8
  Running: 4
  Paused: 0
  Stopped: 4
 Images: 31
 Server Version: 20.10.10
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 1
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runtime.v1.linux runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 5b46e404f6b9f661a205e28d59c982d3634148f8
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: default
 Kernel Version: 4.15.0-162-generic
 Operating System: Ubuntu 18.04.6 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 7.789GiB
 Name: asclepios-sleep
 ID: PDTI:RUE3:FOLP:RQE2:FGNN:BMPA:RYRT:INOB:XA5L:WAMP:XK2Y:BKL5
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: No swap limit support

Additional environment details:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions