ASPNETCORE_ENVIRONMENT in Docker

前端 未结 5 1069
温柔的废话
温柔的废话 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 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"
          }
        }
      }
    }
    

提交回复
热议问题