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?
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?
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:
Reference: ASP.NET Core in a container and Why does aspnet core start on port 80 from within Docker?
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
}