skip to Main Content

I want to make docker-compose (v2.12.2) load env variables from both .env and .env.local

I tried the method mentioned here:

docker-compose --env-file <(cat "./.env" && ([ -f "./.env.local" ] && cat "./.env.local" || echo '')) up -d

But it seems that no envs are loaded and plenty of warnings are thrown:

WARN[0000] The "PGADMIN_DEFAULT_EMAIL" variable is not set. Defaulting to a blank string.
WARN[0000] The "PGADMIN_DEFAULT_PASSWORD" variable is not set. Defaulting to a blank string.
WARN[0000] The "PGADMIN_HOST_PORT" variable is not set. Defaulting to a blank string.
...

Don’t know why. Any help would be appreciated.

vim <(cat "./.env" && ([ -f "./.env.local" ] && cat "./.env.local" || echo ''))

vim shows that two env files are concatenated correctly:

[email protected]
PGADMIN_DEFAULT_PASSWORD=example
PGADMIN_HOST_PORT=8080

PGADMIN_HOST_PORT=8081

OS: centOS 7

2

Answers


  1. Chosen as BEST ANSWER

    Since v2.17, the --env-file flag can be used in multiple occurrences to select more than one env file. Hacking is no longer needed.

    Ref: https://github.com/docker/compose/issues/7326#issuecomment-1446246464


  2. You could try to use a little script like this:
    enter image description here

    I have created two test files with the image and version.
    In the command shown i create a test3 file which combines those two and uses it in the docker-compose as –env-file, afterwards test3 gets deleted again.

    Note: test3 does not get deleted if there is a problem starting the docker container.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search