问题
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