Search code examples
dockerasp.net-coredocker-compose.net-6.0kestrel

Issue with Docker compose and Kestrel in asp.net 6.0 app


I'm trying to run my aspnet 6.0 app using docker(Linux Container on Windows system) and having issues. it runs perfectly fine when I'm not trying to configure kestrel. But whenever i'm trying to add below code, i'm getting issue saying "This site can’t be reached localhost unexpectedly closed the connection."

builder.WebHost.ConfigureKestrel(serverOptions =>
{

    serverOptions.Listen(IPAddress.Any, 5005, options =>
    {
        options.Protocols = HttpProtocols.Http2;

    });
    serverOptions.Listen(IPAddress.Any, 7173, options =>
    {
        options.Protocols = HttpProtocols.Http1AndHttp2;
    });
});

I'm trying to use port 5005 for GRpc purpose and 7173 to expose rest api endpoints. I'm using visual studio 2022 and generated DockerFile by adding docker support.

Here are the docker compose,compose-override yaml and container snaps. enter image description here

enter image description here

enter image description here I have also tried adding https support, but no luck.

 serverOptions.Listen(IPAddress.Any, 7173, options =>
    {
        options.Protocols = HttpProtocols.Http1AndHttp2;
        options.UseHttps("appname.pfx", "password");
    });

Please Note: all of the above lines of code works great when I'm not running on docker.


Solution

  • Had to expose same ports in DockerFile as pointed out in comment by @CodingMytra

    enter image description here

    enter image description here

    enter image description here