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

Time:10-05

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.

CodePudding user response:

I think you can configure this in appsettings.json too:

{
  "Logging": {
    "LogLevel": {
      "Default": "Warning",
      "Microsoft.Hosting.Lifetime": "Information"
    }
  },
  "AllowedHosts": "*",
  "Kestrel": {
    "Endpoints": {
      "WebApi": {
        "Url": "http://localhost:7173",
        "Protocols": "Http1"
      },
      "gRPC": {
        "Url": "http://localhost:5005",
        "Protocols": "Http2"
      }
    }
  }
}

CodePudding user response:

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

  • Related