I've created simple RestAPI in .net core 5.0 - it has only one job, return StatusCode 200 or 500:
[ApiController]
[Route("api")]
public class HomeController : Controller
{
[HttpGet]
[Route("checktrue")]
public IActionResult HealthCheckTrue()
{
return Ok();
}
[HttpGet]
[Route("checkfalse")]
public IActionResult HealthCheckFalse()
{
return StatusCode(500);
}
}
When im building it locally, everything works fine, but as soon as I'm hosting it in docker container, I cannot reach it with Postman.
Dockerfile:
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["HealthCheck/HealthCheck.csproj", "HealthCheck/"]
RUN dotnet restore "HealthCheck/HealthCheck.csproj"
COPY . .
WORKDIR "/src/HealthCheck"
RUN dotnet build "HealthCheck.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "HealthCheck.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
EXPOSE 80
EXPOSE 443
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "HealthCheck.dll"]
When I run docker container it starts normally:
=info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://0.0.0.0:80
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path: /app
(Port is mapped to 5020)
I'm sending the request:
http://localhost:5020/api/checktrue and I get Error: socker hang up
When I'm doing the same request on my machine it works fine.
Do you have any idea how to solve that?
question from:
https://stackoverflow.com/questions/65934411/dockerized-api-returns-socket-hang-up-via-postman 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…