Failed to access the Docker Nanoserver web app.

This question is similar to other questions about Windows networking and how they relate to Docker containers, but I cannot find a solution to my exact problem.

I am creating a Docker container for a new pre-built .NET Core 1.1 application. I have a Dockerfile that builds an application as an image using nano / .NET Core 1.1, but I can NOT access the running application from the windows host.

Usage: Docker for Windows 17.0.31-ce-win10 (11972) on a Windows 10 Pro VM hosted by macOS / vmWare Fusion 8.5.1.

Considering the following Dockerfile

:

FROM microsoft/dotnet:1.1-runtime-nanoserver WORKDIR \app COPY \out . EXPOSE 80 EXPOSE 5000 ENTRYPOINT ["dotnet", "WebApi.dll"]

If I use the command docker run {image} -P 5000:5000

, I get the following output (from a .NET Core 1.1 Hello World application):

Hosting environment: Production Content root path: C:\app Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.

Then, in another terminal window, I issue the following command:

docker inspect {container-name}

where I am getting this noticeable output:

"Networks": { "nat": { "IPAMConfig": null, "Links": null, "Aliases": null, "NetworkID": "246469d0fe2936d87c5a923 "EndpointID": "2401e38f20539ac9fe562e "Gateway": "172.20.64.1", "IPAddress": "172.20.76.30", "IPPrefixLen": 16, "IPv6Gateway": "", "GlobalIPv6Address": "", "GlobalIPv6PrefixLen": 0, "MacAddress": "00:15:5d:33:3e:7a" } }

I cannot access the web application in the following locations:

localhost:5000

, 172.20.76.30:80

,172.20.76.30:5000

Curious, however, if I docker run microsoft/iis

, I can access the {container IP}:80

.

Given the above, what am I doing wrong that is causing my web application container to be inaccessible to the Windows VM host? I can execute ping 172.20.76.30

with the results, and my container is capable ping 172.20.64.1

(its the gateway IP address which matches the Windows VM host), but that as far as I was able to get a confirmation of the path between the two network nodes.

Finally, I'll conclude with the observation that the app works fine in a Windows VM. I can directly specify the same command dotnet WebApi.dll

and access the site using localhost:5000

in Chrome.

+3


source to share


3 answers


Figured out the solution. I changed the base image for Dockerfile

from FROM microsoft/dotnet:1.1-runtime-nanoserver

to FROM microsoft/aspnetcore:1.1.2-nanoserver

and all of a sudden it worked.



I'm a little surprised that this works, as I can run dotnet WebApi.dll

from my local machine without issue, but I'm just glad I found an image / tag that works!

0


source


If it started working because you switched to the image aspnetcore

, then it is more of a port mapping problem than a network one. The aspnetcore base image sets an ASP.NET Core environment variable that tells Kestrel to listen on port 80 rather than bind to localhost:5000

. The key in this last statement is localhost, unless you say otherwise, Kestrel only works for local traffic. The traffic from your host is not local, so it won't work.



If you want to use the image dotnet

instead aspnetcore

for some reason, then you can set the environment variable ASPNETCORE_URL

to something like http://+:5000

or whatever port you want.

+2


source


EDIT

There is currently a limitation on the availability of windows.

Looks like his bad news from the blog link: Docker Loop Back for Windows Containers

Currently, window containers are only accessible via their virtual IP address. Reverse loop access is not yet supported.

0


source







All Articles