title: ASPNETCORE_ENVIRONMENT in Docker
body: <p>i have problems setting the <strong>ASPNETCORE_ENVIRONMENT</strong> variable running my project in a <strong>docker container</strong>. The problem is that the value is always <strong>set/overwritten to "Development"</strong>.</p>
  
  <p>I have tried setting the environment variable in my <strong>Dockerfile</strong> using </p>
  
  <pre><code>ENV ASPNETCORE_ENVIRONMENT test
  </code></pre>
  
  <p>also tried setting the environment variable in my <strong>docker-compose</strong> file using </p>
  
  <pre><code>environment:
        - ASPNETCORE_ENVIRONMENT=test
  </code></pre>
  
  <p>When I set any other environment variable <strong>it works</strong>, for example:</p>
  
  <pre><code>environment:
        - OTHER_TEST_VARIABLE=test
  </code></pre>
  
  <p>I assume that the value for <strong>ASPNETCORE_ENVIRONMENT</strong> variable is overwritten somewhere but I have difficulties finding out where.</p>
  
  <p>I have added Docker support to an existing project and am running the project directly via Visual Studio's Docker/Docker compose option </p>
  
  <p>The project runs on Asp Net Core 2.1</p>
  
  <p>Thanks in advance</p>
  
  <p>My launchSettings.json:</p>
  
  <pre><code>{
    "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
        "applicationUrl": "http://localhost:53183/",
        "sslPort": 0
      }
    },
    "profiles": {
  
      "Docker": {
        "commandName": "Docker",
        "launchBrowser": true,
        "launchUrl": "{Scheme}://localhost:{ServicePort}/api/values"
  
      }
  
    }
  }
  </code></pre>
  
  <p>I also tried adding the environment variable configuration to the launchSettings.json</p>
  
  <pre><code>"Docker": {
            "commandName": "Docker",
            "launchBrowser": true,
            "launchUrl": "{Scheme}://localhost:{ServicePort}/api/values",
            "environmentVariables": {
             "ASPNETCORE_ENVIRONMENT": "test"
        }
          }
  </code></pre>
  
  <p>My Webhost:</p>
  
  <pre><code> public static IWebHost BuildWebHost(string[] args)
          {
             return WebHost.CreateDefaultBuilder(args)
                  .ConfigureAppConfiguration((builderContext,config) =&gt;
                  {
                      config.AddEnvironmentVariables();
                  })
                  .ConfigureLogging((hostingContext, logging) =&gt;
                  {
                      logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
                      logging.AddConsole();
                      logging.AddDebug();
                  })
                  .UseStartup&lt;Startup&gt;()
                  .Build();
  
          }
  </code></pre>
  
  <p>My docker-compose.yml</p>
  
  <pre><code>version: '3.4'
  
  services:
    api:
      image: ${DOCKER_REGISTRY}api
      build:
        context: .
        dockerfile: API/Dockerfile
      environment:
       - ASPNETCORE_ENVIRONMENT=test 
  </code></pre>
  
  <p>My Dockerfile:</p>
  
  <pre><code>FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
  
  WORKDIR /app
  EXPOSE 80
  FROM microsoft/dotnet:2.1-sdk AS build
  WORKDIR /src
  COPY API/API.csproj API/
  RUN dotnet restore API/API.csproj
  COPY . .
  WORKDIR /src/API
  RUN dotnet build API.csproj -c Release -o /app
  
  FROM build AS publish
  RUN dotnet publish API.csproj -c Release -o /app
  
  FROM base AS final
  WORKDIR /app
  COPY --from=publish /app .
  
  
  ENTRYPOINT ["dotnet", "API.dll"]
  </code></pre>
  
  <p>Here is a list of the environment variables in the container</p>
  
  <pre><code>C:\Users\Administrator&gt;docker exec -ti d6 /bin/bash
  root@d6f26d2ed2c3:/app# printenv
  HOSTNAME=d6f26d2ed2c3
  ASPNETCORE_URLS=http://+:80
  test1=asdasd
  test2=dasdasd
  test3=dasdasd
  PWD=/app
  HOME=/root
  NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages
  DOTNET_USE_POLLING_FILE_WATCHER=1
  ASPNETCORE_VERSION=2.1.3
  DOTNET_RUNNING_IN_CONTAINER=true
  TERM=xterm
  SHLVL=1
  PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  ASPNETCORE_ENVIRONMENT=Development
  _=/usr/bin/printenv
  root@d6f26d2ed2c3:/app#
  </code></pre>