Search code examples
dockervisual-studioasp.net-coreazure-container-apps

using visual studio DockerfileRunArguments parameter within launchsettings.json


I am creating container app than uses a Docker container.

ASPNETCORE_ENVIRONMENT="Staging"

I figured I could reference this docker environment file with --env-file dockerfile-staging.conf

"Docker": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
  "DockerfileRunArguments": "--env-file dockerfile-staging.conf",
  "publishAllPorts": true,
  "useSSL": true
}

The environment variable ASPNETCORE_ENVIRONMENT is not set and by default is Development.

I do not see any errors.

If I use the following the aspnetcore environment variable is set as Staging correctly.

Any Idea why may be wrong?

"DockerfileRunArguments": "-e ASPNETCORE_ENVIRONMENT=Staging",

Solution

  • --env-file dockerfile-staging.conf isn't working b/c VS is passing -e ASPNETCORE_ENVIRONMENT=Development as part of the docker run and docker prioritizes the value from the command line over that in the env file. Using -e is working for the same reason.

    As an alternative you can use:

    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}/swagger",
      "publishAllPorts": true,
      "useSSL": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Staging"
      }
    }
    

    The values in environmentVariables are set for just the process, so even if you don't see the value in the container tools window, you will see it in your process.