ASP.NET on Docker Not Serving Web App to Browser
<p>I can't get my ASP.NET web application to get served to my browser when the web app is containerized in Docker.</p>

<p>I'm running a Mac, and I've used Visual Studio Code to create an ASP.NET web application. It's a simple, out-of-the-box demo that is based on the <code>yo aspnet</code> "Empty Application." When run "native" (outside of Docker), this application serves a "Hello World!" to <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a> just fine. In other words, running <code>dnx web</code> starts the web server (Kestrel) and yeilds:</p>

<pre><code>Hosting environment: Production 
Now listening on: http://localhost:5000
Application started. Press Ctrl+C to shut down.
</code></pre>

<p>This is good. Now enter Docker. I seem to have successfully built a Docker image containing the web application, and when I run the container in Docker, I get the same output from Kestrel. Also good, but, I can no longer load the "Hello World!" page in my browser at <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a>. Instead, I get a <code>ERR_CONNECTION_REFUSED</code>. This is fairly obviously because due to the Docker "indirection," there is nothing serving directly to port 5000 anymore. In other words, I think there's an incorrect forwarding configuration, or, I think am misunderstanding the addressing.</p>

<p>I believe that port forwarding is involved in this process. In my Dockerfile, I am using an <code>EXPOSE 5000</code> which I thought would allow me to map my local use of port 5000 to the Docker container's port 5000 using a run command like this:</p>

<pre><code>docker run -i -t -p 5000:5000 container_name
</code></pre>

<p>But that's not the case with <a href="http://localhost:5000" rel="nofollow noreferrer">http://localhost:5000</a> (<code>ERR_CONNECTION_REFUSED</code>). So it occurred to me that Docker is almost certainly not at <code>localhost</code>. I had noticed when Docker loads, it says:</p>

<pre><code>docker is configured to use the default machine with IP 192.168.99.100
</code></pre>

<p>So, I thought I'd try <a href="http://192.168.99.100:5000" rel="nofollow noreferrer">http://192.168.99.100:5000</a>, but again (confusingly?) <code>ERR_CONNECTION_REFUSED</code>. Next, I read an interesting article <a href="https://stackoverflow.com/questions/19897743/exposing-a-port-on-a-live-docker-container">here</a> and I was able to determine from the suggested command </p>

<pre><code>docker inspect container_name | grep IPAddress
</code></pre>

<p>That the container is assigned <code>"IPAddress": "172.17.0.2"</code></p>

<p>So, I thought I'd try <a href="http://172.17.0.2:5000" rel="nofollow noreferrer">http://172.17.0.2:5000</a>. And now we might actually be getting somewhere, because instead of a <code>ERR_CONNECTION_REFUSED</code>, I instead get a spinning hourglass and a resulting timeout. But still no "Hello World!"</p>

<p>What might I be missing?</p>