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.
If you attempt to connect to that port using localhost/127.0.0.1 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 “192.168.99.100” 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: 192.168.99.1 --- 0x25 Internet Address Physical Address Type 192.168.99.100 08-00-27-ae-dc-2f dynamic 192.168.99.255 ff-ff-ff-ff-ff-ff static 184.108.40.206 01-00-5e-00-00-16 static 220.127.116.11 01-00-5e-00-00-fb static 18.104.22.168 01-00-5e-00-00-fc static 22.214.171.124 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.