Dockerized .NET8 API not accessible.
When I try curl I get "(56) Recv Failure. Connection refused by peer."
Docker compose
Dockerfile
What I already tried:
- Running it outside Docker, it works.
- Running curl commands inside Docker, they work.
- Made sure that my app listens to port 8080.
- Changing port from 5282 to 8080. Port 5282 now gets failure 7, 8080 now gets error 56 similarly to what 5282 was getting. "Recv failure. Connection refused by peer."
- Researched online, from what I understand this issue is .NET8 specific and has to do with "Kestrel" not allowing traffic from outside of local device.
I am just using the weatherforecast template, so I have not written any code yet. I am on MacOS Sonoma 14.5 if that helps.
11 Replies
why is entrypoint dotnet watch run?
it should be dotnet Name.dll
probably out/server.dll
and build should probably be Release not Debug
and you should dotnet publish after build
so typically
dotnet restore ...
dotnet build ...
dotnet publish ...
dotnet app.dll
i dont know if watch run could be the cause
somehow i doubt
Check logs and what does it say what urls app is listening on when it starts?
just to be sure that its properly set as expected
and i would check if something is using the port.. in case
dont know for mac.. ss or netstat?
@Patricius for visibility
Hey, thank you for answering, I was in a meeting.
- Why is entrypoint dotnet watch run? This is supposed to be a development environment Dockerfile, dotnet watch is just setting up hot reload. I have another Dockerfile for prod but that one is facing the same issues.
- Why Dockerfile for dev env? Because I have other pieces of Software and with Docker launching the project takes 1 command.
- This is also why I dont do publish and dont use server.dll. I can assure you that outside of Docker these commands and how I run it work fine. Even inside of Docker when I run curl commands everything is fine.
- What do logs say? The logs just show the typical dotnet startup screen:
- Check if something is using the port? I have tried using 5282, 3000 (which I use for other apps I develop) and 8080. I know for sure that nothing else is using 3000.
try with ASPNETCORE_URLS
http://0.0.0.0:8080
insteadSame result:
As far as I know the error 56 shows that connection was established but dropped right away. This error also only occurs on the ports the app listens to, other ports throw error 7.
and in logs?
Now listening on... line
Logs look fine, listening on localhost:8080 as per usual.
its not fine. it should say 0.0.0.0 not localhost
let me change the host within my app and see
oh wow it works
I hate dotnet but more myself for not thinking of this
But also localhost and 0.0.0.0 was kind of in my head as the same thing
localhost mean loop interface
0.0.0.0 mean all interfaces
Okay, thank you very much for resolving this with me. God knows how long it would take me to see this.
Also, amazing cat u have
np!