1

I created an ASP.NETCore API app (.NET 6) and ticked the box to host it in Docker.

The Docker file exposes port 443, and when I run the app in Visual Studio it runs on port 49173. Can someone tell me where I can change that port number?

Peter Morris
  • 20,174
  • 9
  • 81
  • 146

2 Answers2

1

You can use the ENV instruction to add an environment variable to the service container image from the Dockerfile file and set the ASPNETCORE_URLS variable, like this:

enter image description here

Reference: ASP.NET Core in a container and Why does aspnet core start on port 80 from within Docker?

Zhi Lv
  • 18,845
  • 1
  • 19
  • 30
1

In project folder "Properties\launchSettings.json" any debugging configurations such as; environment variables and profiles can be defined there.

note that the file only for debugging purposes if you add any environment variable here It will not affect published app.

An example 'launchSettings.json'

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:3377",
      "sslPort": 3378
    }
  },
  "$schema": "http://json.schemastore.org/launchsettings.json",
  "profiles": {
    "Dev": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      },
      "dotnetRunMessages": "true",
      "applicationUrl": "http://localhost:3377;https://localhost:3378"
    },
    "Prod": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Production"
      },
      "dotnetRunMessages": "true",
      "applicationUrl": "http://localhost:3377;https://localhost:3378"
    }
  }
}

there is also profile for the Debugging on Docker;

"DockerDev": {
  "commandName": "Docker",
  "launchBrowser": true,
  "launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "publishAllPorts": true
}

more detail: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-6.0#development-and-launchsettingsjson