Docker Compose Nested Environment Variable

房东的猫 提交于 2020-01-02 05:01:08

问题


I have an existing app that uses a app config file that looks like:

"ConnectionInfo": {
    "ServerName": "The Server URL",
    "DatabaseName": "The DatabaseName",
    "UserName": "The User Name",
    "Password": "The Password"}

Now, when I have a simple setting, say

"ConnectionString":"My Connection String"

I understand how to override it in the compose.yml file:

environment:
  - ConnectionString=what I want it to be

The question is, how do you set, say, the server name in the top?


回答1:


Please use underscore (__) as the following instead of a colon (:).

environment:
  - ConnectionInfo__ServerName=MyServerName

Please refer to Configuration in ASP.NET Core

For hierarchical config values specified in environment variables, a colon (:) may not work on all platforms. Double underscore (__) is supported by all platforms.




回答2:


You can set nested configurations using a colon to separate the nested sections:

To set the server name here:

"ConnectionInfo": {
    "ServerName": "override this via compose environment"
}

Override it like this:

environment:
  - ConnectionInfo:ServerName=MyServerName


来源:https://stackoverflow.com/questions/45889233/docker-compose-nested-environment-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!