I've created a .net core 2.0 project and configured it to run over HTTPS, however I cannot get Visual Studio to launch the browser with the correct scheme/port when running in Docker debug mode.
The current behaviour is VS always launches on port 80 (HTTP), and I therefore have to manually change the url each time, which is cumbersome.
Program.cs
public class Program {
public static void Main (string[] args) {
BuildWebHost(args).Run ();
}
public static IWebHost BuildWebHost (string[] args) =>
WebHost.CreateDefaultBuilder (args)
.UseKestrel (options => {
options.Listen (IPAddress.Any, GetPort(), listenOptions => {
// todo: Change this for production
listenOptions.UseHttps ("dev-cert.pfx", "idsrv3test");
});
})
.UseStartup<Startup> ()
.Build ();
public static int GetPort() => int.Parse(Environment.GetEnvironmentVariable("Port") ?? "443");
}
Dockerfile
FROM microsoft/aspnetcore:2.0
ARG source
WORKDIR /app
EXPOSE 443
COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "MyApp.dll"]
docker-compose.override.yml
version: '3'
services:
myapp:
environment:
- ASPNETCORE_ENVIRONMENT=Development
- Port=443
ports:
- 443
networks:
default:
external:
name: nat
In the Web API project, again right-click on the project node, and choose Add > Container Orchestrator Support. Choose Docker Compose, and then select the same target OS. In this step, Visual Studio will offer to create a Dockerfile.
depends_on is a Docker Compose keyword to set the order in which services must start and stop. For example, suppose we want our web application, which we'll build as a web-app image, to start after our Postgres container.
For anyone looking for code solution, what causing random port is this line in docker-compose.override.yml:
ports:
- "80"
Just remove it and add your port, for example:
ports:
- "8080:80"
Okay I have found out how to solve this myself.
Right-click the docker-compose project and go to properties.
There you can configure the Service URL that gets launched on run.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With