I cannot get my ASP.NET web application to work with my browser when the web application is containerized in Docker.
I have a Mac and I used Visual Studio code to create an ASP.NET web application. This is a simple, off-the-shelf demo based on the yo aspnet"Empty Application". When running "native" (outside of Docker), this application serves "Hello World!" . http: // localhost: 5000 is just fine. In other words, the launch dnx webstarts the web server (Kestrel) and yeilds:
Hosting environment: Production
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
It's good. Now log into Docker. It seems I have successfully created a Docker image containing a web application, and when I launch the container in Docker, I get the same result from Kestrel. Also good, but I can no longer download "Hello World!" . in my browser http: // localhost: 5000 . Instead, I get ERR_CONNECTION_REFUSED. This is pretty obvious because, due to Docker's "indirectness," there is nothing that serves port 5000 directly. In other words, I think that there is an incorrect forwarding configuration, or, I think, I misunderstand addressing.
I believe that port forwarding is involved in this process. In my Dockerfile I use EXPOSE 5000which, as I thought, will allow me to map the local use of port 5000 to the port of the Docker 5000 container using the start command, for example:
docker run -i -t -p 5000:5000 container_name
But this does not apply to http: // localhost: 5000 ( ERR_CONNECTION_REFUSED). So it occurred to me that Docker was almost certainly not in localhost. I noticed that when Docker boots up, it says:
docker is configured to use the default machine with IP 192.168.99.100
So, I thought I would try http://192.168.99.100/10000 , but again (vaguely?) ERR_CONNECTION_REFUSED. Then I read an interesting article here , and I was able to determine from the proposed command
docker inspect container_name | grep IPAddress
To have a container assigned "IPAddress": "172.17.0.2"
, , http://172.17.0.2:5000. , ERR_CONNECTION_REFUSED -. "Hello World!"
?