Charles Gallo
Charles Gallo

Reputation: 135

Docker Compose Nested Environment Variable

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?

Upvotes: 9

Views: 9742

Answers (2)

idubnori
idubnori

Reputation: 1065

Please use double 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.

Upvotes: 19

officer
officer

Reputation: 2468

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

Upvotes: 4

Related Questions