compose icon indicating copy to clipboard operation
compose copied to clipboard

[BUG] Strange env var behavior when using $var in var

Open cgarnier opened this issue 1 year ago • 1 comments

Description

When i use 2 env files with a var composed of others vars, the resulted var is wrong.

Steps To Reproduce

.
├── docker-compose.yml
├── env1
└── env2
# docker-compose.yml
version: "3.7"
services:
  web:
    image: nginx
    environment:
      - MY_VAR
      - MY_COMP
      - MY_COMP2=BLABLA $MY_VAR
# env1
MY_VAR=1

# env2
MY_VAR=2
MY_COMP="BLABLA $MY_VAR"

Result of the docker compose --env-file env1 --env-file env2 config command:

services:
  web:
    environment:
      MY_COMP: BLABLA 1
      MY_COMP2: BLABLA 2
      MY_VAR: "2"
    image: nginx
    networks:
      default: null
networks:
  default:
    name: ef2_default

MY_COMP should be equal to BLABLA 2

Compose Version

Docker Compose version v2.21.0

Docker Environment

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

Server:
 Containers: 5
  Running: 0
  Paused: 0
  Stopped: 5
 Images: 168
 Server Version: 24.0.7
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 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 logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 3dd1e886e55dd695541fdcd67420c2888645a495
 runc version: v1.1.10-0-g18a0cb0
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.2.0-39-generic
 Operating System: Ubuntu 22.04.3 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 32
 Total Memory: 31.25GiB
 Name: clement-desktop
 ID: 45a4fe3a-c174-4b96-b396-a5fb0219b8ff
 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

cgarnier avatar Jan 18 '24 14:01 cgarnier

related to https://github.com/compose-spec/compose-go/pull/403

the issue here is that we load env files sequentially, and while value set by user's environment has precedence, value from an earlier env file doesn't.

ndeloof avatar Jan 22 '24 14:01 ndeloof

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.

github-actions[bot] avatar Jul 14 '24 00:07 github-actions[bot]