.netdockerdocker-composedockerfileasp.net-apicontroller

Client network socket disconnected before secure TLS connection was established Docker


I have basic web api application with forecast. I want make docker-compose.yml file and work with docker container, but when I make container and try send there request I have "Client network socket disconnected before secure TLS connection was established" Error

My docker-compose.yml :

version: "3.9"
networks:
  online-test-dev:
    driver: bridge
services:
  app: 
    container_name: online-test
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "8080:80"

Dockerfile :

FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
USER app
WORKDIR /app
EXPOSE 80
EXPOSE 8080

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["WebApplication1/WebApplication1.csproj", "WebApplication1/"]
RUN dotnet restore "./WebApplication1/./WebApplication1.csproj"
COPY . .
WORKDIR "/src/WebApplication1"
RUN dotnet build "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./WebApplication1.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "WebApplication1.dll"]

My .Net Controller :

using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
            "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
        };

        private readonly ILogger<WeatherForecastController> _logger;

        public WeatherForecastController(ILogger<WeatherForecastController> logger)
        {
            _logger = logger;
        }

        [HttpGet(Name = "GetWeatherForecast")]
        public IEnumerable<WeatherForecast> Get()
        {
            return Enumerable.Range(1, 5).Select(index => new WeatherForecast
            {
                Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
                TemperatureC = Random.Shared.Next(-20, 55),
                Summary = Summaries[Random.Shared.Next(Summaries.Length)]
            })
            .ToArray();
        }
    }
}

I do this request : GET https://localhost:8080/WeatherForecast And get this Error : Client network socket disconnected before secure TLS connection was established

When I do request to http I get this error : "socket hang up"

I tried disabled Firewall, check ports are available, I not have proxy or vpn, I check container logs and all I saw that container didn't even receive any requests:

2024-01-27 19:14:36 info: Microsoft.Hosting.Lifetime[14]
2024-01-27 19:14:36       Now listening on: http://[::]:8080
2024-01-27 19:14:36 info: Microsoft.Hosting.Lifetime[0]
2024-01-27 19:14:36       Application started. Press Ctrl+C to shut down.
2024-01-27 19:14:36 info: Microsoft.Hosting.Lifetime[0]
2024-01-27 19:14:36       Hosting environment: Production
2024-01-27 19:14:36 info: Microsoft.Hosting.Lifetime[0]
2024-01-27 19:14:36       Content root path: /app

Solution

  • I dont know why but when I change in docker-compose.yml port like this:

    ports:
      - "8080:8080"
    

    Its started work for me