Parameters in .NET Core docker launchSettings.json

Viewed 18338

I am writing an ASP.NET Core application and I have a launchSettings.json file with the following content:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:50251",
      "sslPort": 44349
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "AspNetDockerDemo": {
      "commandName": "Project",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "applicationUrl": "https://localhost:5001;http://localhost:5000"
    },
    "Docker": {
      "commandName": "Docker",
      "launchBrowser": true,
      "launchUrl": "{Scheme}://{ServiceHost}"
    }
  }
}

Question: Where are the { } placeholders substituded and where are the values definied by which they are substituted? What will I have to do if I want to define such values on my own?

3 Answers

Since you're using Visual Studio's Docker integration, you've obviously noted that it randomly selects port mappings for you.

One way to change this is to right click on your asp.net core app, select Add -> Container Orchestration Support. This will attempt to regenerate your Dockerfile and .dockerignore files, which you may decline to do if you've made substantial modifications to your existing files (note: if you have, it may cause other issues with the following instructions). It will also generate some docker-compose settings for you in the form of several yaml files.

In my case, I was interested in the docker-compose.override.yml file it added to the project. Out of the box, it looks something like this:

version: '3.4'

services:
  coreapp:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "80"

The ports: = "80" bit is what interests us. Change it to "<your desired port>:80" to specify a port to use:

version: '3.4'

services:
  coreapp:
    environment:
      - ASPNETCORE_ENVIRONMENT=Development
    ports:
      - "8080:80"

This doesn't answer your question, but if you're asking because you want consistent host port numbers while debugging like I did, you can do this by adding httpPort and sslPort to the launchSettings.json file.

enter image description here

Create a .env file and assign Scheme and ServiceHost.

Scheme=schemename
ServiceHost=localhost
Related