英文:
docker-compose how to pass all env vars from .env file to container without explicitly defining them in compose file?
问题
无法直接将所有环境变量从.env
文件传递到docker-compose.yml
文件。您需要手动将这些环境变量添加到docker-compose.yml
文件中,如下所示:
services:
my_app:
restart: always
image: some_image
hostname: my_app
environment:
- ENV1=blah
- ...
- ENV100=foo
这是因为docker-compose.yml
不会自动从.env
文件中读取环境变量。如果您想要避免手动添加环境变量,可以考虑使用其他方法,如编写脚本来自动生成docker-compose.yml
文件或使用一些工具来处理环境变量的传递。
英文:
Say I have hundreds of env vars defined in .env
file
ENV1=blah
...
ENV100=foo
Is there a way so that docker-compose doesn't require me to define them again in the docker-compose.yml
file?
eg.
services:
my_app:
restart: always
image: some_image
hostname: my_app
environment:
- pass all from .env
答案1
得分: 1
感谢我的同事,我错过了我可以指向服务内的.env
文件的部分
services:
my_app:
restart: always
image: some_image
hostname: my_app
env_file:
- ../.env
英文:
Thanks to my colleague, I missed the section that I can point to an .env
file within a service
services:
my_app:
restart: always
image: some_image
hostname: my_app
env_file:
- ../.env
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论