ASP.NET Core container does not answer on the published port
curl: (56) Recv failure: Connection reset by peerShort answer
Since .NET 8 the ASP.NET Core container images listen on port 8080, not 80. A mapping such as -p 8000:80 now points at nothing. Map to 8080, or set ASPNETCORE_HTTP_PORTS to the port you want. Also make sure the app binds to all interfaces, not only localhost.
Fix it fast
1Find out which cause you have
Show which container port is mapped, then look at the app's own startup log. The port the app listens on must equal the right-hand side of the mapping.
docker port my-app docker logs my-app2Match what you see, then jump to its fix
- 1
The mapping ends in :80 and the image is based on an 8.0 or newer ASP.NET imageThe mapping still targets port 80Fix - 2
ASPNETCORE_HTTP_PORTS is set but the app still does not answer; startup code calls WebHost.CreateDefaultBuilderThe app uses the older WebHost builder and ignores the new variableFix - 3
The log or configuration shows a URL like http://localhost:5000, and the connection from the host is reset or refusedThe app is bound to localhost inside the containerFix
- 1
What does the error look like?
curl: (56) Recv failure: Connection reset by peerThe container is running and logs no error, but the mapped host port never answersWorked on .NET 7, stopped after changing the base image to 8.0
Cause 1 of 3
The mapping still targets port 80
1Check
The images moved the default listening port to 8080 so the app can run as a non-root user. Port 80 is a privileged port. A mapping to container port 80 reaches no listener.
docker inspect --format '{{.Config.Env}}' my-app2Fix
Map to 8080. If other tools expect port 80, set ASPNETCORE_HTTP_PORTS to 80 instead. Change the same number in Compose or Kubernetes manifests.
docker run --rm -d -p 8000:8080 my-app
# or keep 80 inside the container
docker run --rm -d -p 8000:80 -e ASPNETCORE_HTTP_PORTS=80 my-app
# compose.yaml
services:
web:
image: my-app
ports:
- "8000:8080"3Verify
The published port answers from the host.
curl -I http://localhost:8000Confirmed by learn.microsoft.com
Cause 2 of 3
The app uses the older WebHost builder and ignores the new variable
1Check
Apps built with the older WebHost.CreateDefaultBuilder API do not read ASPNETCORE_HTTP_PORTS. Because ASPNETCORE_URLS is no longer set by the image, they fall back to http://localhost:5000.
grep -rn "CreateDefaultBuilder" --include=*.cs .2Fix
Set ASPNETCORE_URLS, not ASPNETCORE_HTTP_PORTS, for these apps.
docker run --rm -d -p 8000:80 -e ASPNETCORE_URLS=http://*:80 my-app3Verify
Request the mapped port again.
curl -I http://localhost:8000Confirmed by learn.microsoft.com
Cause 3 of 3
The app is bound to localhost inside the container
1Check
A listener on localhost accepts connections only from the same network namespace. Docker forwards the published port to the container's network address, so a localhost-only app is never reached. Look for urls in appsettings.json, ASPNETCORE_URLS and launchSettings-derived values.
docker exec my-app printenv | grep -i aspnetcore
grep -rn "localhost" appsettings*.json2Fix
Bind to every interface: a wildcard host in the URL, or just the port variable.
ENV ASPNETCORE_HTTP_PORTS=8080
# or
ENV ASPNETCORE_URLS=http://*:80803Verify
Rebuild, rerun and request the published port.
docker build -t my-app .
docker run --rm -d -p 8000:8080 my-app
curl -I http://localhost:8000Confirmed by learn.microsoft.com
How do I stop it coming back?
- Write the container port once (ASPNETCORE_HTTP_PORTS in the Dockerfile) and reuse that number in run commands, Compose and Kubernetes.
- After moving a base image to a new major version, read its breaking-changes page before the first deploy.
- On Azure container hosts, set the target port the same way (for App Service, WEBSITES_PORT).
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
Related fixes
Servers
A Docker container port is not reachable from the host or network
The service answers inside the container but not from the host
A container port is closed to the outside until you publish it with -p or a ports entry.
3 causes, each with a fixServers
A containerized ASP.NET Core app says the framework Microsoft.AspNetCore.App was not found
Framework: 'Microsoft.AspNetCore.App', version '6.0.0' (x64)
The app asks for a shared framework the final image does not have.
3 causes, each with a fixServers
docker build cannot find a local file or log in to a private NuGet feed
The parameter is incorrect
A Docker build sees only the build context, minus anything in .dockerignore, so files outside it are not found.
4 causes, each with a fixServers
docker build fails with CS5001, no entry point found
error CS0017: Program has more than one entry point defined.
CS5001 means the compiler built an executable project and found no entry point.
4 causes, each with a fixServers
MSB1011 when dotnet build or publish runs inside a Docker build
dotnet build or dotnet publish fails in a RUN step of the Dockerfile
dotnet build and dotnet publish pick a project by searching the current folder.
3 causes, each with a fixServers
dotnet says it cannot find any installed .NET SDKs (in Docker or on a server)
A compatible .NET SDK was not found
The dotnet command found a runtime but no SDK that fits.
3 causes, each with a fix