Description
Up to version 2.23.3 docker compose would end up loading both the .env file of the CWD, and the .env file at the same level of the $COMPOSE_FILE in use
Since version 2.24.0 only the first .env il loaded, but the other .env file at the same level of the $COMPOSE_FILE is not sourced, causing those env variables to be empty strings
Example on 2.24.0 running docker compose build
WARN[0000] The "IMAGE_NAME" variable is not set. Defaulting to a blank string.
WARN[0000] The "IMAGE_TAG" variable is not set. Defaulting to a blank string.
[+] Building 0.0s (0/0) docker:default
invalid tag "/:": invalid reference format
Steps To Reproduce
I have a setup with the following tree
.
├── .env
└── stack
├── development
│ ├── docker-compose.yaml
│ ├── .env
│ └── node.env
├── Dockerfile
└── local
└── node.env
The main .env file is automatically loaded if I run docker compose in that directory, and this .env file set-up the $COMPOSE_FILE variable to specify which docker compose file to use
.env
#!/usr/bin/env sh
export COMPOSE_FILE="${COMPOSE_FILE:-stack/development/docker-compose.yaml}"
while stack/development/.env contains some ENV variables used inside the stack/development/docker-compose.yaml file
stack/development/.env
#!/usr/bin/env sh
# Docker
export COMPOSE_PROJECT_NAME=projectname
# Image
export IMAGE_NAME="${IMAGE_NAME:-backend}"
export IMAGE_TAG="${IMAGE_TAG:-latest}"
stack/development/docker-compose.yaml
version: "3.8"
services:
backend:
image: $IMAGE_NAME:$IMAGE_TAG
build:
context: ../../
dockerfile: stack/Dockerfile
restart: unless-stopped
Compose Version
Docker Compose version 2.24.2
Docker Environment
Client:
Version: 24.0.7
Context: default
Debug Mode: false
Plugins:
buildx: Docker Buildx (Docker Inc.)
Version: 0.12.1
Path: /usr/lib/docker/cli-plugins/docker-buildx
compose: Docker Compose (Docker Inc.)
Version: 2.24.2
Path: /usr/lib/docker/cli-plugins/docker-compose
Server:
Containers: 7
Running: 0
Paused: 0
Stopped: 7
Images: 33
Server Version: 24.0.7
Storage Driver: btrfs
Btrfs:
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: 71909c1814c544ac47ab91d2e8b84718e517bb99.m
runc version:
init version: de40ad0
Security Options:
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.7.0-arch3-1
Operating System: Arch Linux
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 14.97GiB
Name: 8boi
ID: E3K6:GCEU:3MNV:N4R3:FBUO:HDYW:AW3O:V26O:2LKW:T2LW:EP4C:T5UL
Docker Root Dir: /var/lib/docker
Debug Mode: false
Username: abinsula
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
Anything else?
No response
Description
Up to version
2.23.3docker compose would end up loading both the.envfile of the CWD, and the.envfile at the same level of the$COMPOSE_FILEin useSince version
2.24.0only the first.envil loaded, but the other.envfile at the same level of the$COMPOSE_FILEis not sourced, causing those env variables to be empty stringsExample on 2.24.0 running
docker compose buildSteps To Reproduce
I have a setup with the following tree
The main
.envfile is automatically loaded if I rundocker composein that directory, and this.envfile set-up the$COMPOSE_FILEvariable to specify which docker compose file to use.envwhile
stack/development/.envcontains some ENV variables used inside thestack/development/docker-compose.yamlfilestack/development/.envstack/development/docker-compose.yamlCompose Version
Docker Environment
Anything else?
No response