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

docker-compose.yml env_file option not process properly #9767

Closed
tomeus opened this issue Aug 19, 2022 · 1 comment
Closed

docker-compose.yml env_file option not process properly #9767

tomeus opened this issue Aug 19, 2022 · 1 comment
Assignees
Labels

Comments

@tomeus
Copy link

tomeus commented Aug 19, 2022

Description
I have an issue with a list of env files in docker-compose.yml

Based on the documentation I expect another behaviour. Documentation says this

For the same variable specified in two env files, the value from the last file in the list MUST stand.

But for some reason variable defined in .env is never overwritten.

I have these files
docker-compose.yml

version: '3.9'
services:
  app:
    image: php
    env_file:
      - ./.env
      - ./.env.local

.env

ENV_FILE_VAR=1
ENV_BOTH_FILE_VAR=1

.env.local

ENV_LOCAL_FILE_VAR=2
ENV_BOTH_FILE_VAR=2

Steps to reproduce the issue:

  1. Create a folder with the files as are described above
  2. Run docker-compose up -d
  3. Check env variables inside the container, e.g. run docker-compose run app env

Describe the results you received:
Env variables inside the container look

ENV_FILE_VAR=1
ENV_LOCAL_FILE_VAR=2
ENV_BOTH_FILE_VAR=1

Describe the results you expected:

Env variables inside the container should look like

ENV_FILE_VAR=1
ENV_LOCAL_FILE_VAR=2
ENV_BOTH_FILE_VAR=2

Additional information you deem important (e.g. issue happens only occasionally):

Output of docker compose version:

Docker Compose version v2.7.0

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.8.2)
  compose: Docker Compose (Docker Inc., v2.7.0)
  extension: Manages Docker extensions (Docker Inc., v0.2.8)
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc., 0.6.0)
  scan: Docker Scan (Docker Inc., v0.17.0)

Server:
 Containers: 7
  Running: 7
  Paused: 0
  Stopped: 0
 Images: 23
 Server Version: 20.10.17
 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: 2
 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.runc.v2 io.containerd.runtime.v1.linux runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
 runc version: v1.1.2-0-ga916309
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.104-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 3.842GiB
 Name: docker-desktop
 ID: KCU3:QAZ4:FBLT:XX4S:VFA6:CMZH:CBIE:XRGF:HMRK:3D7G:QV6A:HV3Z
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5000
  127.0.0.0/8
 Live Restore Enabled: false

Additional environment details:

@milas
Copy link
Contributor

milas commented Aug 26, 2022

Thanks for the report. We have dramatically improved the environment variable logic in recent releases and fixed some long outstanding issues (see #9636).

This issue should now be fixed in the latest releases:

# docker compose version --short
2.10.1

# docker compose run app
ENV_LOCAL_FILE_VAR=2
ENV_FILE_VAR=1
ENV_BOTH_FILE_VAR=2

For Docker Desktop users, Compose v2.10.1 will ship with the next release.

@milas milas closed this as completed Aug 26, 2022
@milas milas added the kind/bug label Aug 26, 2022
@milas milas self-assigned this Aug 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants