skip to Main Content

Edit: Problem reduced to appearing when changing from .Net6 to .Net8. Changing from .Net6 to .Net7 works fine. But why?

I’ve tried to follow this tutorial.
https://learn.microsoft.com/en-us/visualstudio/containers/tutorial-multicontainer?view=vs-2022

The have pushed their code to
https://github.com/MicrosoftDocs/vs-tutorial-samples/tree/master/docker/ComposeSample

I download and it works.
I change .Net version of projects AND linux versions building/running the projects from .Net6 to .Net8 and I get Connection Refused calling WebApi.

It smells of more strict defaults, but I find it hard to pinpoint and fix.

So: Can you download above sample and get it running for most recent .Net, currently .Net8? And of course I’d like to understand why this is/was a problem.

Older part of question:

I’ve got the WebFrontEnd running and attempting to call the WebApi. Upon calling the WebApi, the FrontEnd get Connection Refused.

The WebApi is running correctly when I point the browser to http://localhost:53845/Counter . I suspect the problem is that the WebApi is available on a different port than expected from WebFrontEnd. As I understand it, the WebFrontEnd expects to find the WebApi on port 80?

How can I debug the communication when it happens inside the docker environment?

Calling code:

using (var client = new System.Net.Http.HttpClient())
{
    // Call *mywebapi*, and display its response in the page
    var request = new System.Net.Http.HttpRequestMessage();
    // webapi is the container name
    request.RequestUri = new Uri("http://webapi/Counter");
    var response = await client.SendAsync(request);
    string counter = await response.Content.ReadAsStringAsync();
    ViewData["Message"] = $"Counter value from cache :{counter}";
}

2

Answers


  1. If you’re using version 8 ASP.NET containers, the default port has changed from 80 to 8080.

    If that’s the case, you should use http://webapi:8080/Counter instead.

    More info here.

    Login or Signup to reply.
  2. This is listed as a breaking change, which is logical as 80 is a privileged port. It should never have been 80.

    https://learn.microsoft.com/en-us/dotnet/core/compatibility/containers/8.0/aspnet-port

    I find it clearer and to just specify ports yourself for which you have 3 options.

    Specify "Urls" in appsettings.json

    {
      "Urls": "http://0.0.0.0:30000"
    }
    

    code it into your startup pipeline or just directly

    .UseUrls("http://0.0.0.0:30000") or app.Urls.Add("http://0.0.0.0:30000")

    set environment variable in your container with ENV

    ASPNETCORE_URLS=http://0.0.0.0:30000

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search