compose icon indicating copy to clipboard operation
compose copied to clipboard

env_file does not allow /dev/null

Open rdaysky opened this issue 5 years ago • 6 comments

docker-compose.yml does not allow env_file: /dev/null, because it tests the provided path with os.path.isfile, and /dev/null is not a regular file. This breaks the following use case:

env_file:
    - defaults.env
    - ${EXTRA_ENV_FILE:-/dev/null}

which, if not for the overly strict check, would allow EXTRA_ENV_FILE=extra.env docker-compose up, while also letting the user run the service without overriding the environment. There is a workaround of adding a blank file to version control and using that instead, but it’s clumsy.

I suggest that env_file: /dev/null be permitted, either by allowing any path that exists, or by special-casing /dev/null (so it also works on Windows).

rdaysky avatar Jan 02 '20 22:01 rdaysky

Engine do support passing --env-file /dev/null so compose should do the same

ndeloof avatar Jan 03 '20 10:01 ndeloof

You can use a .env file instead.

ulyssessouza avatar Jan 23 '20 22:01 ulyssessouza

Engine do support passing --env-file /dev/null so compose should do the same

@ndeloof I'm aware this issue is old and closed but I'm not sure of the accuracy of this statement.

antonio@ark:~$ docker --version
Docker version 20.10.6, build 370c289
antonio@ark:~$ docker run --rm --env-file=/dev/null alpine:latest sh -c 'echo $FOO'

antonio@ark:~$ docker run --rm --env-file=blah alpine:latest sh -c 'echo $FOO'
i am defined

At the time this issue was submitted, docker engine would have been 19.03 so:

antonioabella@swarm-test:~$ docker --version
Docker version 19.03.10, build 9424aeaee9
antonioabella@swarm-test:~$ docker run --rm --env-file=/dev/null alpine:latest sh -c 'echo $FOO'

antonioabella@swarm-test:~$ docker run --rm --env-file=bla alpine:latest sh -c 'echo $FOO'
hi

Engine seems to handle --env-file=/dev/null just fine in both versions. This appears to be a failing of compose, not engine.

a-abella avatar Jun 16 '21 17:06 a-abella

@a-abella yes, I fully agree. As I said "docker run does, so compose should do the same"

As the reported use-case was to be able to pass extra environment file, @ulyssessouza suggestion to use a .env file or --env-file option is relevant, still docker-compose should not FAIL when env file is set to /dev/null

ndeloof avatar Jun 17 '21 04:06 ndeloof

@ndeloof Oh, I misread your comment. my mistake

a-abella avatar Jun 17 '21 04:06 a-abella

Can this be reopen? This issue has been closed without addressing the problem

@ulyssessouza

pladaria avatar Aug 30 '22 13:08 pladaria

My bad: as I tested on Mac OS, obviously --env-file=/dev/null worked, but I eventually got bootcamp setup with Docker Desktop Windows so I can give it a try on Microsoft OS, and :

Microsoft Windows [version 10.0.19045.2251]
(c) Microsoft Corporation. Tous droits réservés.

C:\Users\nicolas>docker run --env-file /dev/null alpine
docker: open /dev/null: Le chemin d’accès spécifié est introuvable.
See 'docker run --help'.

So, for sure we can do some magic in Docker Compose, but we should not implement things that the docker/cli doesn't support.

Alternatively, considering your initial feature request, we could manage empty values set in env_file list, i.e

env_file:
    - defaults.env
    - ${EXTRA_ENV_FILE}

when EXTRA_ENV_FILE si not set, we could ignore empty entry in the list and only load defaults.env

ndeloof avatar Dec 12 '22 21:12 ndeloof

Closing this issue in favor for https://github.com/docker/compose/issues/9181

ndeloof avatar May 03 '23 15:05 ndeloof