i have problems setting the ASPNETCORE_ENVIRONMENT variable running my project in a docker container. The problem is that the value is alwa
Thanks for your comments, I solved my issue. It was just my mistake.
My problem was that when I added Docker-Support to my project I already had a Dockerfile included in the project.
When VS generated files for Docker-support, there was a second Dockerfile created, and one of the Dockerfiles was renamed to "Dockerfile.original".
I was using the "Dockerfile" visible in the solution explorer (which was somehow mapped to the "Dockerfile.original" file in the filesystem)
It seems that in the background my changes where written to "Dockerfile.original" but this file wasn't used while docker-compose was running. It used the empty generated Dockerfile that wasn't visible in the Solution explorer.
It works for me by configuring ASPNETCORE_ENVIRONMENT
with command dotnet CoreDocker.dll --environment="X"
Try to change dockerfile
like below:
ENTRYPOINT ["dotnet", "CoreDocker.dll", "--environment=X"]
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"
}
}
}
}
In the docker-compose.override.yml file, you should find something like that:
version: '3.4'
services:
webapplication1:
environment:
- ASPNETCORE_ENVIRONMENT=Development # <==
I had the same problem, I use Rider, I had the environment variable only on the docker-compose file in the service environment section.
What was happening on my end was I did not have ConnectionStrings set in my appsettings.Development.json
so it defaulted to the appsettings.json
file's ConnectionStrings.
I after adding the proper connection string to the development json file everything worked fine with the docker-compose up command. Hope this helps someone as well.