Skip to content

[BUG] --env-file option is ignored from docker compose --env-file=file.env up #10838

@astrolemonade

Description

@astrolemonade

Description

Hey!
docker compose --env-file=file.env up is ignoring the --env-file option.

Steps To Reproduce

  1. have a docker-compose.yaml file that should use some environment variables from an environment variables file.
    example:
version: '3.9'
services:
  node:
    image: node:18
    container_name: live_dev
    # it was specifically chosen to hang the container so that we can inspect it
    command: tail -F anything
  1. have an file.env file:
    example:
MY_VAR=my_var
  1. have the following directory structure:
[~/live_dev] $ tree -a
.
├── docker-compose.yaml
└── file.env

1 directory, 2 files
  1. run the docker compose --env-file=file.env up
  2. enter the container via docker exec -it live_dev /bin/bash
  3. run printenv to see if MY_VAR exists
[~/live_dev] $ docker exec -it live_dev /bin/bash
root@741ec06639ca:/# printenv
HOSTNAME=741ec06639ca
YARN_VERSION=1.22.19
PWD=/
HOME=/root
TERM=xterm
SHLVL=1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NODE_VERSION=18.17.0
_=/usr/bin/printenv
  1. notice that MY_VAR doesn't exist

Compose Version

Docker Compose version v2.18.1

Docker Environment

Client: Docker Engine - Community
 Version:    24.0.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.11.1
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.18.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose

Server:
 Containers: 4
  Running: 4
  Paused: 0
  Stopped: 0
 Images: 14
 Server Version: 24.0.1
 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: 0cae528dd6cb557f7201036e9f43420650207b58
 runc version: 5fd4c4d144137e991c4acebb2146ab1483a97925
 init version: 0b44d36
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.3.12-241.current
 Operating System: Solus 4.4 Harmony
 OSType: linux
 Architecture: x86_64
 CPUs: 12
 Total Memory: 15.5GiB
 Name: catalin
 ID: QGPZ:6HOM:HUOC:EWS6:42UO:UZ47:5PEO:NKUW:VUDH:LQQ7:GI5X:RAY6
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

Adding env_file to the docker-compose.yaml and running docker compose up loads the file and makes the variable present.

version: '3.9'
services:
  node:
    image: node:18
    env_file:
      - file.env
    container_name: live_dev
    # it was specifically chosen to hang the container so that we can inspect it
    command: tail -F anything

Did some investigation and it seems it was removed from build, up and down some time ago(maybe in the Python version and got ported to the Go version, I am not sure). #6800 and also has something to do with #10650
I don't know if this is supposed to happen.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions