Access a Linux Docker Container From the Windows Docker-Host Host using Port Publishing (–P)

Well, that’s a fun title but I think it most accurately describes the topic of this post.  To explain further, I’m running Docker Toolbox 1.12.3 on Windows 7 Professional which utilizes VirtualBox (5.0.26) to host a Linux VM as the Docker Host in Linux. 

Lots of blog posts mention you can use the –p option with docker run to bind a port between the container and the host.–p—expose

If you attempt to connect to that port using localhost/ as these posts suggest, it fails:



The port binding is between the container and Docker host.  Our host is running in the VirtualBox virtual machine, so you have to connect to the IP of the VM instead of “localhost”.  Localhost is for the Windows operating system running VirtualBox, the Docker-Host Host.

Find the VM Ip

The first way I found to get the IP for the VirtualBox virtual machines was to open the terminal for the VM, run ifconfig and try each IP address.


In this case, we find the IP address “” for the “eth1” network correctly bound to the right port.  Not sure if you can always assume “eth1” will be the right one but worth trying first.


Another option I found was to lookup the Network Adapter name in VirtualBox and then running arp from a command prompt to find all IPs on that network.


>arp -a
Interface: --- 0x25
  Internet Address      Physical Address      Type        08-00-27-ae-dc-2f     dynamic        ff-ff-ff-ff-ff-ff     static            01-00-5e-00-00-16     static           01-00-5e-00-00-fb     static           01-00-5e-00-00-fc     static       01-00-5e-7f-ff-fa     static

The dynamic IP is the winner. 

Docker Noobs Unite!

Granted I’m fairly new to Docker, I still struggle with questions/issues that I assume Docker experts think is trivial.  Regardless, I wanted to share my learnings for all my fellow Docker noobs. 

I also recently blogged about accessing a Docker container by its own IP which is provided by the private network that is created by the Docker host.

If this post was helpful or you have further questions please let me know in the comments below or on social media.

1 thought on “Access a Linux Docker Container From the Windows Docker-Host Host using Port Publishing (–P)”

  1. Pingback: Intro to Distributed Config with Consul on ASP.NET COre – dotnet catch

Leave a Reply