-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.env file referenced underneath env_file in a compose file is being parsed when file is not used. #8713
.env file referenced underneath env_file in a compose file is being parsed when file is not used. #8713
Comments
I can't reproduce it with the same OS and compose version. The mkdir -p .config/.myapp/
printf 'DEBUG=debug' > .config/.myapp/.env
printf 'services: {debug: {image: alpine:3.14, network_mode: none, command: ["echo", "DEBUG=$DEBUG"], init: true}}' > docker-compose.yaml
docker compose run --rm debug
|
Hello @beyondmeat! Could you please add a complete minimal testcase so we could try to reproduce it? |
docker-compose.yml
docker-compose.whoami.yml
./.config/whoami/.env
DO NOT use the "whoami" profile. In this situation, even though whoami isn't going to be pulled or started, it's reading the env_file linked in a (unused) compose file and using it like it was a env file for compose. env_file in a compose service is env vars for the container, not used by compose it. Which causes the entire pull/up command to fail complaining about invalid env vars it shouldn't even be looking at. I was able to test this out by simply commenting out the env_file section in the compose files (that aren't being currently used unless activated with a profile). Watchtower is the only thing that should be pulled and started in this case (since the whoami profile isn't active) but yet, it's reading the files underneath docker-compose.whoami.yml env_file section and parsing them like it's the compose .env file |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
I can confirm that this issue still exists in docker compose v2.3.4. # debug.compose.yaml
services:
debug:
image: alpine
env_file:
- ./debug/.env # debug/.env
this/should/not/be/parsed=debug # compose.yaml
services:
debug-only:
extends:
file: ./debug.compose.yaml
service: debug
profiles:
- debug
hello:
image: alpine docker compose up
# unexpected character "/" in variable name near "this/should/not/be/parsed=debug\n" The |
This issue has been automatically marked as not stale anymore due to the recent activity. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Retested the use-case from @page-down and I can confirm this bug is still there with |
This issue has been automatically marked as not stale anymore due to the recent activity. |
Anybody can fix it? I using: v2.13.0 |
@beyondmeat while this bug seems relevant, I wonder: if env_file is invalid, even service is disabled by profile, how do you use this service? We could prevent compose to parse this file if service is disabled, but still this means this service config is basically "dead code" (actually, "dead config") that you will never be able to use for concrete actions. to prevent this we would need to delay call to resolveEnvironment after profiles have been applied and some services excluded from configuration. |
@ndeloof in my case, I use the profiles keyword to use it, but in this case the point is that I'm not using it. It's more of a dynamic service that I use sometimes but not always. Basically, I have a git repo that has a main docker-compose that has individual service compose files that are used across multiple servers but each only use a portion of the services that is set by using the profile feature. I basically use it like a library if that makes sense. |
re-opening this issue, as compose-spec/compose-go#338 allows to fix it, but still need to update compose codebase accordingly |
It seems like this issue is still present with docker compose 2.33.1 Example docker compose: services:
serviceA:
image: nginx:latest
serviceB:
image: nginx:latest
env_file:
- /doesnotexist/.env Command: $ docker compose up -d serviceA
env file /doesnotexist/.env not found: stat /doesnotexist/.env: no such file or directory
exit status 1 |
Could you re-open this please ? |
@iTrooz ` |
Description
In Compose V2 -2.0.0.0, .env files that are underneath other folders are being picked up and parsed by compose. In my case these .env files are stored underneath compose-stack/.config/.myapp/.env and don't have anything to do with compose.
Steps to reproduce the issue:
Describe the results you received:
Describe the results you expected:
Not to include the .env file since it's not in the top working dir or in the same folder as the compose file.
Additional information you deem important (e.g. issue happens only occasionally):
I could rename the non-compose .env files but that feels like a workaround.
Output of
docker compose version
:Output of
docker info
:Additional environment details:
I store my compose file in a folder, in that folder I have .config, .appdata, .secrets, etc. I use a 1 folder nested approach, so everything that has to deal with the compose stack is all nested in 1 folder structure. Compose v1 and 2.0RC3 didn't have this issue.
The text was updated successfully, but these errors were encountered: