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?
In Docker Compose, IT admins can use environment variables to generalize configurations for different situations, deployment environments and security contexts without editing the main project file(s) manually. Variables can either be passed as command-line arguments -- suitable for only a few parameters -- or via a .
When we launch our Docker container, we can pass environment variables as key-value pairs directly into the command line using the parameter –env (or its short form -e). As can be seen, the Docker container correctly interprets the variable VARIABLE1.
The .env file feature only works when you use the docker-compose up command and does not work with docker stack deploy . Both $VARIABLE and ${VARIABLE} syntax are supported.
Using Multiple Docker Compose Files Use multiple Docker Compose files when you want to change your app for different environments (e.g., dev, staging, and production) or when you want to run admin tasks against a Compose application. This gives us one way to share common configurations.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With