Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

.net - Dockerized API returns socket hang up via Postman

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...