I migrated my application to .NET 8.0, ran it locally and it works perfectly.
Then I created an image, the container. As a result, the page that was working before now returns a "1.2.3.4 refused to connect."
Before, when I was in .NET 7.0, the API worked.
My basic DockerFile
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build-env
WORKDIR /app
COPY *.csproj ./
RUN dotnet restore
COPY . ./
RUN dotnet publish -c Release -o out
FROM mcr.microsoft.com/dotnet/aspnet:8.0
WORKDIR /app
RUN chmod -R 755 /app
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "myapi.dll"]
My api runs on port 8860
49de1a3ce47c myapi "dotnet myapi.dll" 13 minutes ago Up 13 minutes 0.0.0.0:8860->80/tcp, :::8860->80/tcp
Logs:
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://[::]:8080
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
.NET 8 ASP.NET Core Docker images have a breaking change - Default ASP.NET Core port changed from 80 to 8080:
So you need either to change port mapping
8860:8080
or change the port for the container (for example by passing-e ASPNETCORE_HTTP_PORTS=80
argument todocker run
or addingENV ASPNETCORE_HTTP_PORTS=80
afterFROM mcr.microsoft.com/dotnet/aspnet:8.0
).