Access a Docker Container from the Docker for Windows Host

I have recently been researching NetflixOSS and found Netflix provides many Docker images that make setting up a local development environment really easy.  In order to run the images on Windows, I installed Docker for Windows which is a Hyper-V based Docker host for Windows.  This all installed without issue and I was able to run the NetflixOSS images:

image

The problem is you can’t access the service websites from the Docker for Windows host.

image

Docker for Windows creates a private network for itself in Hyper-V.  Both the Docker host and containers are issued IPs in this private network.  By default, the computer running Docker for Windows cannot access this private network.  After several days a digging I found a forum post which describes how to open a route between the private network and the host OS by running the following command from an elevated command prompt:

route add 172.17.0.0 mask 255.255.0.0 10.0.75.2 -p

The first IP address (172.17.0.0) is a reference to the default Docker subnet.  The mask specifies the level at which you want IPs routed. The last IP is the address for the Docker host.  You can find this by opening Hyper-V Manager, selecting the MobyLinuxVM virtual machine and viewing the Networking tab at the bottom of the window.  The –p flag specifies the route should persist across reboots of the machine.

image

After adding the route, you can run route print to see it was added correctly:

image

If you set the IPs correctly, the Docker container should now be accessible from a browser on your development machine.  Note I have noticed it can take a minute or two for the site to resolve the first time.

image

 

I hope this post was helpful.  I will be digging into Docker and NetflixOSS with .NET Core in the future so stay tuned for more related posts.

3 thoughts on “Access a Docker Container from the Docker for Windows Host”

  1. Pingback: Selenium with .NET Core – dotnet catch

  2. Pingback: Access a Linux Docker Container From the Windows Docker-Host Host using Port Publishing (–P) – dotnet catch

  3. Pingback: ASP.NET Core with Docker Container | Ryan Yong

Leave a Reply