https://rancher.com/ logo
#rancher-desktop
Title
# rancher-desktop
h

helpful-butcher-75556

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:
Copy code
services:
 busybox:
   container_name: busybox
   image: busybox
   env_file: .env-compose
   environment:
     ZA: "in compose"
   profiles:
     - 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
Copy code
; .env file
ZA=.env file
ZB=.env file
ZC=.env file
.env-compose
Copy code
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
Copy code
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
Copy code
busybox  | ZA='in compose'
If I set env_file to .env I get
Copy code
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
dockerd
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.
Copy code
busybox |ZA='in compose'
busybox |ZB='.env-compose file'
busybox |ZC='.env-compose file'
busybox |ZD='.env-compose file'
3 Views