Shubhanshu Rastogi
Shubhanshu Rastogi

Reputation: 2413

AppSettings for a .NET Core Project not overriding in Docker Container

The appsetting for a .NET Core project can be overridden in Docker Container using the Environment variable. For Example

Appsetting.json

{
    "Logging": {
        "LogLevel": {
            "Default": "Debug"
    }
}

DockerFile (Incase of Base OS as Ubuntu)

ENV Logging__LogLevel__Default "Warning"

DockerFile (Incase of Base OS as Windows)

ENV Logging:LogLevel:Default "Warning"

The above thing works perfectly fine for all my project but suddenly I find the configurations are not getting overridden using Docker file defined Environment Variables.

The Probable Reason I can think of - I created a Project of ASP.NET Core 3.0 and something broke in it.

Upvotes: 3

Views: 1831

Answers (1)

Shubhanshu Rastogi
Shubhanshu Rastogi

Reputation: 2413

The Reason was surely not the ASP.NET Core migration but there was a mistake in using the Configuration builder. One need to specifically provide config.AddEnvironmentVariables(); in Program.cs so that the environment variables could be overwritten by the dockerfile

It's a small reason but sometime it could hit hard as it not possible to debug it in a production environment and also debugging is quite hard with docker environment.

A good source to understand Environment Variable in .NET Core. Please Refer here

Upvotes: 4

Related Questions