Boris Eetgerink

March 23, 2023

Setting the environment of a .NET Docker container

A .NET (web) app has a configuration file for each environment (appsettings.EnvironmentName.json). The application determines which environment it runs in through the ASPNETCORE_ENVIRONMENT, the DOTNET_ENVIRONMENT environment variable or through other means. Because of that, one build/publish of an application is able to run in every environment. But how does that work in a Docker container?

The answer is a lot shorter than the introduction. The -e flag sets the environment variables:

docker run -dp 8081:80 -e "DOTNET_ENVIRONMENT=Production" image:tag

About Boris Eetgerink

Hey, this is my C# .NET blog. I don't have a comments system, but you can contact me at boriseetgerink at hey dot com.