Maybe you are not understanding the purpose of
EXPOSE
in the Dockerfile. Read the second solution, and the link about exposing ports for ASP.NET Core and then continue reading the rest of the answer here.
See this repository of mine, and check how this works.
GitHub - afzaal-ahmad-zeeshan/nodejs-dockerized: Dockerized Node.js application.[
^], I did not expose any port and if you run the application using,
$ docker run -d --name test afzaalahmadzeeshan/express-nodejs:latest
$ docker inspect test
If you send a request to the IP address for this container on the port 5000 (because that is what I have set for this web app in the app.js file; check it!), you will see that it works just fine, even though I never exposed a port, any port.
The reason why this requires you to expose 80 and then expect send traffic to port 80 only is because the app inside your container is listening on port 80. In order to change the port from 80 to, say, 5000, you also need to modify the internals of ASP.NET Core web application and make it listen on port 5000.
One more thing, the port binding in Docker helps in case where you are trying to load balance the services, or running the service and are configuring external services to forward traffic on a specific port (25 for email, 80 for HTTP, etc. etc.). In every other case, it is not necessary. The port that your application (the application that you containerized) decides where it has to listen.
-p 5000:80
just lets you send a request on 5000 and let Docker forward that to 80 on container—here the fun starts,
if nothing is listening on port 80 in the container, nothing will happen.
I also invite you to read my article on this introductory topic about Docker,
DockerOps: Getting Started with Docker[
^].