[BUG] docker compose on docker desktop not reading --env-file
Description
when using docker compose with docker desktop, it seems to be ignoring the --env-file arg and instead using the default .env file found in the directory. Im running docker desktop on windows.
my .env file looks like this:
VERSION=local
ENV=local
my .env_dev file looks like this:
VERSION=dev
ENV=dev
my dev docker-compose has this snippet:
services:
my_app:
container_name: my_app_${ENV}
image: "my_app:${VERSION}"
build:
context: ..
dockerfile: .devcontainer/Dockerfile
target: my_app_dev
args:
ENV: ${ENV:-local}
environment:
ENV:${ENV:-local}
PYTHONPATH:${PYTHONPATH}
my dockerfile looks like this:
FROM python:latest as base
ARG ENV
....
....
FROM base as my_app_dev
COPY "./.devcontainer/.env_$ENV" .
When then run the following in the directory where the compose and .env and .env_dev files are:
docker system prune -f
docker compose --env-file .env_dev build --no-cache```
I get this error:
=> ERROR [my_app my_app_dev 1/3] COPY ./.devcontainer/.env_local .
There is no .env_local file. im expecting that it would be .env_dev. It seems to still be reading the .env file. Why is it not reading the ENV value from the .env_dev file, which should have the value 'dev' and so the line it should be COPY ./.devcontainer/.env_dev .
Steps To Reproduce
- create the above files
- one windows (with docker desktop) run
docker compose --env-file .env_dev build --no-cachein the docker-compose folder
Compose Version
Docker Compose version v2.21.0
Docker Environment
Client: Docker Engine - Community
Version: 24.0.6
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: 1
Running: 1
Paused: 0
Stopped: 0
Images: 2
Server Version: 24.0.6
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: cgroupfs
Cgroup Version: 1
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: 8165feabfdfe38c65b599c4993d227328c231fca
runc version: v1.1.8-0-g82f18fe
init version: de40ad0
Security Options:
seccomp
Profile: unconfined
Kernel Version: 5.15.90.1-microsoft-standard-WSL2
Operating System: Docker Desktop
OSType: linux
Architecture: x86_64
CPUs: 16
Total Memory: 19.25GiB
Name: docker-desktop
ID: 27fa49f8-2bb6-4fc3-8a08-342f8072a5a4
Docker Root Dir: /var/lib/docker
Debug Mode: false
HTTP Proxy: http.docker.internal:3128
HTTPS Proxy: http.docker.internal:3128
No Proxy: hubproxy.docker.internal
Experimental: false
Insecure Registries:
hubproxy.docker.internal:5555
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
WARNING: daemon is not using the default seccomp profile
Anything else?
No response
So this seems to only happen when trying this from docker-in-docker. if I run the docker-compose command from the host, it seems to read the --env-file arg correctly and passes those variables onto the dockerfile when building
im in a vscode .devcontainer - based on latest debian/bookworm image. i am mounting the docker.sock from the host into that devcontainer
Try running docker compose --env-file .env_dev config to confirm the resulting model has the expected variables interpolated
Try running
docker compose --env-file .env_dev configto confirm the resulting model has the expected variables interpolated
It does not from the docker-in-docker session (it shows env_local, which implies its ignorning the --env-file arg and using the default .env). outside, it does show the expected value based on the --env-file argument
What does docker compose version show inside your devcontainer?
What does
docker compose versionshow inside your devcontainer?
the version is listed above in my original post: Docker Compose version v2.21.0
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.