Is it possible to use different .env for different

2019-07-15 07:10发布

I have a situation where it would be nice to have multiple .env files, one for each service in my docker-compose.yml. Is there any way to specify a different filename to use? Can this be done on the level of individual services?

I attempted to use the env_file tag, unfortunately, this sets variables for use in Dockerfile and at run-time. The .env file, on the other hand, sets variables to be expanded in docker-compose.yml.

2条回答
我想做一个坏孩纸
2楼-- · 2019-07-15 07:30

Unfortunately, it's not possible to specify an alternative name for the .env file. I've wanted to be able to swap that out too, but you can see in the source code that's it's coded directly to .env.

Is there a reason you want to split out substitution variables per service? It feels like you should be able to put the variables for all of your services into a single .env file.

查看更多
不美不萌又怎样
3楼-- · 2019-07-15 07:38

Yes, with the env_file service option.

You can pass multiple environment variables from an external file through to a service’s containers with the ‘env_file’ option, just like with docker run --env-file=FILE ...:

web:
  env_file:
    - web-variables.env

Source docs: https://docs.docker.com/compose/environment-variables/#the-env_file-configuration-option

查看更多
登录 后发表回答