Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address' for release version Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address' for release version docker docker

Unable to bind to http://localhost:5000 on the IPv6 loopback interface: 'Cannot assign requested address' for release version


After 2 days of digging, I found the problem. It was not obvious at all. I use a appsettings.json, and I use model to read it, and inject it into the IConfiguration at Startup.cs

    var appConfigs = Configuration.GetSection("App").Get<AppConfigs>();    services.AddSingleton<IConfiguration>(Configuration);

The line that was breaking everything is the second one:

    services.AddSingleton<IConfiguration>(Configuration);

According to this answer, after .net core 2, it was no longer necessary to add it. Adding it didn't mess up during debugging, but once it ran inside the container, it caused the error listed above. I just removed the second line, and the application remained working fine, and it started working perfectly inside the container as well.

Creating projeto_sistemacadastroapi_1 ... doneAttaching to projeto_sistemacadastroapi_1sistemacadastroapi_1  | info: Microsoft.Hosting.Lifetime[0]sistemacadastroapi_1  |       Now listening on: http://[::]:80sistemacadastroapi_1  | info: Microsoft.Hosting.Lifetime[0]sistemacadastroapi_1  |       Application started. Press Ctrl+C to shut down.sistemacadastroapi_1  | info: Microsoft.Hosting.Lifetime[0]sistemacadastroapi_1  |       Hosting environment: Productionsistemacadastroapi_1  | info: Microsoft.Hosting.Lifetime[0]sistemacadastroapi_1  |       Content root path: /app