ASPNETCORE_ENVIRONMENT in Docker

前端 未结 5 1053
温柔的废话
温柔的废话 2021-01-17 07:35

i have problems setting the ASPNETCORE_ENVIRONMENT variable running my project in a docker container. The problem is that the value is alwa

相关标签:
5条回答
  • 2021-01-17 07:52

    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.

    0 讨论(0)
  • 2021-01-17 08:01

    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"]

    0 讨论(0)
  • 2021-01-17 08:01

    Visual Studio Docker Tooling

    In case you use the Docker integration for Visual Studio (debug container from within VS) you need to pay special attention to the defaults.

    Default Environment Variables

    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.

    .Net-Core 3.0 Generic Host

    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"
          }
        }
      }
    }
    
    0 讨论(0)
  • 2021-01-17 08:08

    In the docker-compose.override.yml file, you should find something like that:

    version: '3.4'
    
    services:
      webapplication1:
        environment:
          - ASPNETCORE_ENVIRONMENT=Development # <==
    
    0 讨论(0)
  • 2021-01-17 08:11

    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.

    0 讨论(0)
提交回复
热议问题