2022年10月27日 星期四

Docker compose .env confusion

Background

I want to specify the location of .env file for variable substitution of docker-compose yml file, there is a need to separate .env, .production.env for different usage scenarios.


Problems

Some responses in stackoverflow quotes "env_file" keyword and --env-file tag which are not the same thing as .env file, env_file and --env-file tag only pass environment variables to containers, but not variable substitutions of docker-compose file, they are totally different things.


Solutions

cat the env file content to the docker compose file to read contents of .env with custom name. E.g.: alt.env

env $(cat alt.env) docker-compose up --build


References

https://stackoverflow.com/a/67495905/2361494

沒有留言:

張貼留言