compose icon indicating copy to clipboard operation
compose copied to clipboard

Variables pulled when using an env_file override, now override environment settings in docker-compose.yml

Open lingmann opened this issue 3 years ago • 2 comments

Description

With Docker Compose V2, variables pulled in via an env_file override, now override environment variables specified in docker-compose.yml.

Steps to reproduce the issue:

Test Files

$ cat docker-compose.yml
version: '2.4'
services:
  test:
    image: alpine
    environment:
      PGHOST: sql

$ cat docker-compose.override.yml
version: '2.4'
services:
  test:
    env_file:
      - .env

$ cat .env
PGHOST=localhost

Describe the results you received:

When using Docker Compose V2, PGHOST is set to localhost from the .env file and ignores the value specified in the docker-compose.yml environment.

$ docker compose version
Docker Compose version v2.2.1

$ docker compose -f docker-compose.yml -f docker-compose.override.yml config
services:
  test:
    environment:
      PGHOST: localhost
    env_file:
    - .env
    image: alpine
    networks:
      default: null
networks:
  default:
    name: test_default

Describe the results you expected:

PGHOST should be set to sql similar to behavior with Docker Compose V1

$ docker-compose -v
docker-compose version 1.29.2, build 5becea4c

$ docker-compose -f docker-compose.yml -f docker-compose.override.yml config
services:
  test:
    environment:
      PGHOST: sql
    image: alpine
version: '2.4'

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

Output of docker compose version:

Docker Compose version v2.2.1

Output of docker info:

Client:
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc., v0.7.1)
  compose: Docker Compose (Docker Inc., v2.2.1)
  scan: Docker Scan (Docker Inc., v0.14.0)

Server:
 Containers: 4
  Running: 1
  Paused: 0
  Stopped: 3
 Images: 4
 Server Version: 20.10.11
 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: 7b11cfaabd73bb80907dd23182b9347b4245eb5d
 runc version: v1.0.2-0-g52b36a2
 init version: de40ad0
 Security Options:
  seccomp
   Profile: default
  cgroupns
 Kernel Version: 5.10.76-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 4
 Total Memory: 15.64GiB
 Name: docker-desktop
 ID: 4CIP:X5EB:G7AH:O4KV:SDBN:SBWT:H4HH:76CX:I5JX:3HOO:RZY4:KYQK
 Docker Root Dir: /var/lib/docker
 Debug Mode: true
  File Descriptors: 43
  Goroutines: 45
  System Time: 2022-01-04T03:48:54.665447375Z
  EventsListeners: 3
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 Registry: https://index.docker.io/v1/
 Labels:
 Experimental: true
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

lingmann avatar Jan 04 '22 03:01 lingmann

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 10 '22 12:07 stale[bot]

This issue has been automatically closed because it had not recent activity during the stale period.

stale[bot] avatar Jul 31 '22 23:07 stale[bot]

This issue has been automatically closed because it had not recent activity during the stale period.

stale[bot] avatar Aug 13 '22 11:08 stale[bot]