Comments (4)
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.
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:
- read the local
.env
- set the
COMPOSE_FILE
if necessary - look for the
COMPOSE_FILE
, walking up the directory tree if necessary, until it's found - 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.
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.
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)
- [BUG] docker compose pull shows wrong visual representation of data to be downloaded HOT 2
- [BUG] Build secrets from env vars loaded from .env file are empty HOT 2
- Referencing Cluster volumes HOT 1
- Print logs when docker compose up is waiting HOT 1
- [docs] kill examples use docker-compose
- deleted
- [BUG] Docker compose not showing python logs until container finishes. HOT 2
- [BUG] Build fails with Bad File Descriptor HOT 2
- Many colons in serial path worked before, but stopped working a week or so ago[BUG] <title> HOT 1
- How to use Docker Compose in GitHub Action? HOT 3
- [BUG] docker compose only tries to load the `.env` located near the first `docker-compose.yml` file even if it not in the PWD HOT 2
- Allow Compose behaviour to match CLI and create networks without being used or requiring defined services HOT 1
- [BUG] <title>When a service stopped no dependants from other project stopped. HOT 1
- [BUG] Release 2.29.2 is missing artifacts and descriptions HOT 1
- [BUG] `docker compose wait` waits for ALL containers, not just the first HOT 1
- [BUG] Compose Develop does not sync changes to services without build section HOT 2
- Startup script command in dockerfile/docker-compose.yml HOT 2
- [BUG] warn , the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion HOT 2
- [BUG] docker compose up --no-deps recreates container HOT 2
- [BUG] docker compose looking for envs when it should not HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compose.