Fix: Docker Connection Refused to ASP.NET Core App

Published: Jun 05, 2026 · By Kumar Kunal

The Error

curl inside container:

curl: (7) Failed to connect to localhost port 5000: Connection refused

Quick Fix - 1 Min

1. Use http://0.0.0.0:5000 not localhost in Dockerfile. 2. ASPNETCORE_URLS=http://+:80 env var. 3. Expose port in docker run: -p 8080:80

Root Cause

Kestrel binds to localhost by default. Docker container localhost!= host localhost.

Found this helpful?

Master C# with our complete course. Real apps, real skills, job-ready in 2 hours.

Share this fix: Twitter LinkedIn

Comments on Fix: Docker Connection Refused to ASP.NET Core App (0)

No comments yet. Be the first to share your thoughts!