i have problems setting the ASPNETCORE_ENVIRONMENT variable running my project in a docker container. The problem is that the value is alwa
In case you use the Docker integration for Visual Studio (debug container from within VS) you need to pay special attention to the defaults.
When the tooling is starting the debugger with a docker run [..]
command, it supplies an -e "ASPNETCORE_ENVIRONMENT=Development"
argument. You can overwrite this environment variable in the Properties/launchSettings.json
.
Even though I can't see it in the issued command, in my testing I experienced another default variable ASPNETCORE_URLS=http://+:80
as well.
A good starting point to read about VS Docker Tooling is this blog post and the official documentation.
When you use the generic host in .Net-Core 3.0 you might encounter issues when you use the new generic DOTNET_ENVIRONMENT
variable, since you will have two environments specified then. This can be hard to debug. So what I like to do is to unset all defaults initially and start fresh in my Properties/launchSettings.json
:
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"profiles": {
"Docker": {
"commandName": "Docker",
"environmentVariables": {
// Overwrite default VS Docker Tools environment variables first (ASPNETCORE_ENVIRONMENT=Development; ASPNETCORE_URLS=http://+:80)
// https://www.paraesthesia.com/archive/2019/06/18/tips-on-container-tools-for-visual-studio/
"ASPNETCORE_ENVIRONMENT": "",
"ASPNETCORE_URLS": "",
"DOTNET_ENVIRONMENT": "Production",
"DOTNET_URLS": "http://+:80"
}
}
}
}