Giter Site home page Giter Site logo

Comments (4)

ndeloof avatar ndeloof commented on September 23, 2024

This topic is a never ending issue it seems :'(
Any attempt to "fix" it comes with some users being frustrated by their usage being broken.

As .env file is loaded from "project directory" (base of your compose file) and compose looks for a compose file in the parent folder(s) there's no reason sub/.env would be loaded. But we also allow COMPOSE_FILE to be declared .. by a local .env file, so this one has to be parsed before we actually know project directory - a chicken vs egg problem here. This is the reason sub/.env used to be included in the interpolation, but it never has been documented we "merge" both sub/.env and <project directory>/.env - and obviously some started relying on this 😓

For your scenario, I would recommend to use an explicit --env-file flag to select customer-specific configuration, so you don't rely on this "feature"

from compose.

jpetazzo avatar jpetazzo commented on September 23, 2024

I don't understand; it looks like the original behavior (read both .env files and merge) satisfied everyone (by fitting to both use-cases: "I want a global .env at the top-level" and "I want a more specific .env in a subdirectory").

Furthermore, the original behavior did not have the chicken-and-egg problem that you describe, since it was possible to:

  1. read the local .env
  2. set the COMPOSE_FILE if necessary
  3. look for the COMPOSE_FILE, walking up the directory tree if necessary, until it's found
  4. read the global .env if it's in a different directory)

Or am I missing something?

The current behavior (read only the top-level .env) does have a chicken-and-egg problem indeed, since the .env might set the COMPOSE_FILE which might make the top-level directory irrelevant. But that problem didn't exist with the original implementation 😅

from compose.

ndeloof avatar ndeloof commented on September 23, 2024

Actually compose v1 only used the local .env file and ignored the one in project directory. This used to bring some issues (as all other paths are relative to project directory) so we changed this, which brings some more issues
Still "load local .env" was required so users can set COMPOSE_ variables - but there's no other reason we should load both env file, until we decide to introduce this as an explicit, documented, tested feature. I agree this covers your usage very well, I just wonder about impacts as this area already suffered many regressions.

from compose.

ndeloof avatar ndeloof commented on September 23, 2024

Also to be mentioned: the logic you describe (read the local .env, then read the global .env if it's in a different directory) won't give you what you expect, as latest read would then set WIN=root, while you're expecting is an environment override. This used to work as the whole local .env was set as os.Env

from compose.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.