I cannot run ASP.NET Core application on Docker using command prompt

I want to run a basic ASP.NET Core application not from Visual Studio but from command prompt but I can’t - I get ERR_EMPTY_RESPONSE in browser: I tried on THREE different computers. I think it can be related to the newest version of .NET Core which I am using.

This is my application:

I executed commands:
docker build -t dockerdemo .
docker run -d -p 8080:80 --name myapp dockerdemo

And http://localhost:8080/ gives me ERR_EMPTY_RESPONSE each time.

Please help. I am new in Docker.

I’M not a C# developer, but didn’t you run the application on port 8080?

Or is it just an external port in that settings?

The error message indicates the application is not listening on that port or listening but don’t answer.

Make sure the port mapping is right. The right side of the mapping is the port that the app is listening on inside the container.

I think the application is listening on port 8080 because I see on a console:

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

I had to use:

docker run -d -p 5000:8080 dockerdemo

And now:
http://localhost:5000/WeatherForecast

WORKS !!! :slight_smile:

I see I my previous answer was confusing.

I meant that the app was not listening on the port (port 80) to which you forwarded the host port (port 8080)

Good that you could still get to the solution I tried to suggest :slight_smile: because I wouldn’t have understood myself either.