09/30/2022, 2:19 PM
I'm using Rancher Desktop 1.5.1 and have seen odd environment variable precedence for compose. My compose file looks like this:
   container_name: busybox
   image: busybox
   env_file: .env-compose
     ZA: "in compose"
     - test
   command: ['sh', '-c', 'set']
I have .env and .env-compose files as shown below, and set local environment variables ZA=OS and ZB=OS
; .env file
ZA=.env file
ZB=.env file
ZC=.env file
ZA=.env-compose file
ZB=.env-compose file
ZC=.env-compose file
ZD=.env-compose file
When running this I get the following variables in the container
busybox  | ZA='in compose'
busybox  | ZB='OS'
busybox  | ZC=.'env file'
busybox  | ZD=.env-compose file'
Note that the priority is: 1. environment in compose 2. the environment variable at the CLI 3. the .env file 4. the .env-compose
If I remove env_file from the compose file. I only get this. No .env, no OS variables
busybox  | ZA='in compose'
If I set env_file to .env I get
busybox  | ZA='in compose'
busybox  | ZB='OS'
busybox  | ZC='.env file'
This doesn't match the Docker spec for precedence. Any ideas? I forgot to mention I'm using
so I can play with compose Profiles and this is on an M1 Mac.
I switch to containerd and it looks more like the spec.
busybox |ZA='in compose'
busybox |ZB='.env-compose file'
busybox |ZC='.env-compose file'
busybox |ZD='.env-compose file'