Docker.github.io: env_file list order / precedence in docker-compose.yml

Created on 18 May 2017  路  8Comments  路  Source: docker/docker.github.io

File: compose/compose-file/index.md, CC @londoncalling

Hey there! Please speak briefly to whether the env files towards the top or bottom of the list override env values that may be declared in multiple files. Thanks!

areCompose

Most helpful comment

The order of the files is significant, yes. It will be hello

All 8 comments

@shin- @dnephin can you address this question? I can add the details to the docs, but don't know the answer.

I'm not sure I understand the question. env always overrides env_file

@dnephin, given the following declaration in docker_compose.yml:

services:
  some-service:
    env_file:
      - a.env
      - b.env

And the following files:

# a.env
FOO=1

and

# b.env
FOO=hello

Will $FOO be 1 or hello?

The order of the files is significant, yes. It will be hello

Can we have this said explicitly on the docs please?

https://docs.docker.com/compose/compose-file/compose-file-v2/#env_file

@alanjds This was already added explicitly to the docs in the Version 3 Compose file per the referenced PR ^^ #3517, and is published at: https://docs.docker.com/compose/compose-file/#env_file

I've added further clarification in #3822, and will go ahead and update v2 and v1 with those same changes as well, in this case.

@londoncalling I see. Thanks.

Updates are merged, so this should be published soon. Thanks, @alanjds .

Was this page helpful?
0 / 5 - 0 ratings