-
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 option #6170
Comments
Good idea, this one. |
Current plans for environment files are spelled out here: #745 (comment) While I'm not entirely excluding the possibility of an |
From what I understand that solution doesn't really solve an other requirement (which I assume many have): having many docker-compose file in the same folder and being able to launch them using different .env files. To bring a concrete example, I have a How would you deal with this scenario? For reference: docker-compose.yml
|
On a related note, the '.env' filename is really way too generic to have as a default. Where .env is used for different things, and without the ability to override it makes the whole environment variable mechanism unusable. |
Am I missing something ? Is the --env-file option already valid? If it is not, the documentation says otherwise |
No that's different. With At least according to my understanding. Maybe someone can add more details. |
To expand on what @nmaro is saying and provide a summary of the ticket status as I understand it, @codextremist what this issue is discussing is being able to do something like so: project folder:
docker-compose up --env-file=dev.env Which would pass some variables from version: '3'
services:
mysql:
image: mysql:5.7
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD} (passed in from dev.env or prod.env, etc)
MYSQL_DATABASE: ${MYSQL_DATABASE}
... Right now only one This proposal is distinct from the I strongly support this proposal since this would make many people's beta/prod/dev setup easier given the ability to pass env files by command line :) Current hacks involving symlinking .env to the env file you want to have active are error-prone and less clear and explicit than a CLI flag would be. To maintain backwards compatibility, |
@shin- just wondering what is the current status on the --env-file option. |
@nolazybits Assuming you're talking about the Yes, you can specify multiple env files for a service and have them be combined. See the documentation. |
Have to copy it in place since docker/compose#6170
Ah yeah got mixed up. Thanks for your reply though :) So to come back to this issue (no actual --env-file)
docker-compose offers a -f to get the docker-compose.yaml and to me those yaml file are going in par with the env files, so it would be nice to be able to specify the env files those docker-compose file are needing. Copied from another issue Hello, I would really like to see a --env-file option that could be use the same way as -f (i.e multiple --env-file could be loaded). My use case is the following: Thanks again @shin- |
I'm interested in using --env-file as well. |
Can we please have this essential feature? The --env-file CLI option would complement the docker compose's ability to replace ${ENV_VARIABLE} with the variable's value. This somehow is essential in our many use cases. |
@shin- is there possibility to load multiple env files ONLY for processing
the values will be populated into container and there won't be possibility to dynamically change application's behavior with environmental variables from So what I would like to do is loading env files only for creating environment, but without passing them to container.. Any suggestions? |
Another case. I moved docker-related environment variables to
Now, when running project, I get I know I can run |
What if we can have a direct key value in docker-compose which specifies which file to use for substituting values in docker-compose file. Example -
So for every different machine The practical use case that I face daily is while deploying |
Guys, please, let's create the way how load specific Now I have clean project with folder structure:
And I need just pass variables to each environment. My temporary solution: https://gist.github.com/landsman/514731b1cd94d379589a533a6b2d663f This functionality missing me here a lot! 🙏 |
Please add the For now, for those looking for a workaround, I'm using the env $(cat .env.test) docker-compose up |
My preference would also be for the --env-file option. I have a use case where this would be great i.e. deploying alfresco into containers. Alfresco uses a properties file of its own to configure the services called alfresco-global.properties. This is just a PROP=VAL file the same format as the .env file. It would be great to use this same global.properties file to also enable the configuration for docker-compose rather than having multiple files with repeated properties for both the compose setup and the service setup. Steve |
My preference would also be for the --env-file option. |
I agree |
Other more specific filenames should be also read by default to avoid collisions with other tools parsing |
And why not adding |
AFAIS #6535 does not cover all use cases mentioned here. It brings basic functionality of overriding default env file which is loaded during build. If I'm correct, it doesn't allow specifying multiple env files to be loaded, which was described above in the example where Am I correct? |
A generic way to solve this is to implement something like kustomize but for Docker, then users are free to patch their YAML files as they please. I also came here looking for a way to specify an env file for different environments and I think the workaround seems to be duplicating my docker-compose.yml files in an ugly way. |
Is it possible to also load env variables from a .yaml file. Like this node library does? |
just saying i'm doing this via systemd:
compose:
which was the only way i found to use the env vars from a file directly in the compose file while executing it (i dont like the .env file, i want multiple env files named by my convention for multiple environments) |
That's actually a great idea although although you'd have to somehow resolve the cyclic dependency when someone sets eg.
|
This is my charm and working. Thank you! |
To resolve the error env $(cat .env.test | grep "#" -v) docker-compose up |
just saying that all of those solutions with env in front are breaking auto-completion of docker-compose which i dont wanna miss |
i think lets just make a VSCode extension to do this for us and call it a day |
This is my workaround that I put in my .bashrc: export COMPOSE_HOME=/home/jgrote/docker
alias dc="env PWD=$COMPOSE_HOME $(cat $COMPOSE_HOME/.env | grep -v '#' | tr '\n' ' ') docker-compose"
alias dcup="dc up -d"
complete -F _docker_compose dc I can use dc for my special one, and then docker-compose if I need to use a non-special one. @Elyytscha this doesn't break autocompletion :) |
The feature has been implemented already #6535 |
Has it been included in a release yet or is there a roadmap for when it will be? This still doesn't work for me and I don't see it anywhere in the docs, it's not listed here: https://docs.docker.com/compose/reference/up/ |
@adamerose
|
Is Docker Compose version 1.26.2 --EDIT-- My mistake, sorry. I stupidity messed up the options order... 😞 It should be |
@iraklisg Check out this link https://docs.docker.com/compose/environment-variables/. |
@MexsonFernandes the link doesn't mention Furthermore, pointing people to documentation in issues is rude, especially without an in-page anchor, and especially since few posts above the matter of documentation being outdated was raised. It's rude for two reasons. First, documentation changes over time and there is no guarantee that the information you saw will be there when someone else follows the link, and second, it's implies on your part an assumption that someone was either stupid or lazy as to not check relevant documentation before seeking answers in a Github issue. |
@bmarkovic my bad. I will make sure to read off and mention proper links out here. 👍🏼 |
|
Running a similar version below, thought I'd mention:
and then only add one ENV_FILE var when running ENV_FILE=.env.test docker-compose run web |
This looks like a popular request and a glaring omission from the docker-compose workflow, with no solution presented. Can someone explain why is this issue has been closed??? |
Looks like it has been resolved. |
This option has been discussed in a couple of tickets but never had a ticket for itself.
One should be able to execute
docker-compose up --env-file=.env.test
(perhaps multiple env files)to override the usage of
.env
file.The text was updated successfully, but these errors were encountered: