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
Interpolate Variables set by environment or env_file #3435
Comments
Would https://docs.docker.com/compose/env-file/ not do it ? |
For this enhancement request, I would also like the The default command-line supported for a static Purposefully keeping examples simple (would use something more complex, e.g. local dev mount points, test assets, persistent store links, etc): db.env POSTGRES_VERSION="9.4" docker-compose.yml version: '2'
services:
database:
env_file:
- ./db.env
image: "postgres:${POSTGRES_VERSION}" Or another example app.env APP_ROOT="/app" docker-compose.yml version: '2'
services:
web:
env_file:
- ./app.env
build: .
command: ${APP_ROOT}/wrapper.sh
volumes:
- ./logs/:${APP_ROOT}/logs
ports:
- "8080:8080" Currently, this outputs that following in 1.7.1:
|
Ok, now I understand what you want. That makes sense to me. |
Not sure I understand, as I thought |
Right, so you can get there by mapping those specific .env files into the container via the -v flag. Then inside your container your startup script always sources in .env. |
+1 for this feature |
I have been using Thus given above, you'd have: version: '2'
variables:
- APP_ROOT="/app"
services:
web:
env_file:
- ./app.env
build: .
command: ${APP_ROOT}/wrapper.sh
volumes:
- ./logs/:${APP_ROOT}/logs
ports:
- "8080:8080" I used |
I support fixing the hardcoding of the env_file per: #3399 I did some digging and don't think it would take a ton of effort, but am not familiar enough(or maybe a lack of more complex coding skills) with the codebase to implement. I was thinking of something along the lines of the logic of the process_service method in compose/config/config.py being called/passing the service_dict to compose/config/environment.py:from_env_file to replace: env_file = os.path.join(base_dir, 'env') with env_file = os.path.join(base_dir, service_dict['env_file']) Obviously there's a few steps between that,happy to offer help/collaborate with anyone else on this too. I am also happy to open a new issue, but thought this issue made the most sense to add this to. |
While I understand the use cases for such a feature, I don't think it's a good idea to overload |
Totally agree, but the behavior I'm currently seeing isn't inline with the docs (I am happy to open a separate issue if you would like). Basically I'm trying to specify a custom ENV file that's not "${PWD}/.env" https://docs.docker.com/compose/compose-file/#/env-file env_file:
- ./common.env
- ./apps/web.env
- /opt/secrets.env Leads me to believe the below should work My compose file: version: '2'
services:
APP:
env_file: './jarrod.env'
build:
args:
NODE_ENV: ${NODE_ENV}
context: ../../APP
image: APP:${git_branch}
ports:
- "XX:XX"
environment:
- NODE_ENV=${NODE_ENV} my jarrod.env file:
When I try to build the image:
|
@jpooler This is working normally. We should perhaps make the docs clearer, but this isn't a bug. |
@aanand you mean you can't use |
I hate wrapper scripts as well, but I don't think that compose yml file is good place to define vars. IMHO that would lead to completely unreadable mix of vars (who is setting or reading from where?). I have been using .env file heavily and if compose would interpolate env_file.yml with .env/shell vars the same way it does in compose.yml I would be so happy. :) (#3934). Now if ADD/COPY would be able to pipe through something like setenv (https://github.com/subfuzion/envtpl) I wouldn't need any post-scripts at all. |
To clear the scope, this is not about docker variables for the Dockerfile, which are already handled. This is for having the In any automation system, you want to have DRY (don't repeat yourself) and also a way to have defaults that can be overridden. Docker Compose added this in 1.7.0 with the My initial confusion when writing this up was around the time the feature was released, and the documentation (still likely) was less than adequate. It was easy to confuse the So TL;DR, don't have two files, a |
Workaround solution: Put this in a
The |
Yeah, the workaround solution from @jpswade works perfectly but is there any progress with providing native reading variables from multiple files by |
The workaround from @jpswade means you cannot override environment variables though. |
I personally think that It's better to separate Docker infrastucture (which compose represents) from config values. It's, for example, much safer because you can copy/paste Interpolation itself should work better, but this is totally different story... |
A year of no activity on this issue :( Would absolutely love for this to be a feature. (bump) |
* Testing env_file for reuse of variables See docker/compose#3435 (comment) * Update to env setup Rely on env_file for all environment variables.
this feature would be really helpful! (bump) |
+1 |
As noted by @aanand #3435 (comment), there seem to be some confusion here. variable substitution as requested here is well supported using an |
Just got here following the rabbit hole 😅 I would also love to be able to have variables interpolated from an Seeing this issue is closed I'm following the path of @jpswade
But, reading @jacobrask 's comment...
Made an updated version of the
Differences from the original version:
|
Why is this closed? |
Obviously, but the request here is that we should be able to specify an alternative file name rather than |
already the case: |
Never tried this with compose! Thanks for the tip 👍 |
It's pretty inexplicable for variables to interpolate implicitly from |
|
Does anyone found a solution for this? Sorry but it is rude to close unresolved issue. |
|
Summary
Enhancement request that environment variables set from within the
docker-compose.yml
file could be used elsewhere.This would make docker-compose more dynamic instead of current static nature. Right now have to compose some wrapper script to compose docker-compose to compose containers.
Docker-Compose file examples
The text was updated successfully, but these errors were encountered: