Search code examples
macosvirtualboxboot2docker

Access Docker container running on OS X via boot2docker in Windows virtual machine


Overview:

Host: Mac OS X running boot2docker and Docker
Guest: Windows 7

The Problem:

For my web-development I have set up a docker container via boot2docker on OS X. Within OS X I can access my docker services via boot2docker.

Running boot2docker ip, I get:

The VM's Host only interface IP address is: 192.168.59.103

I am running a Django application on port 1234 (I have mapped the port 5000 on the docker image to port 1234 on my Mac) which I can access within OS X in an web-browser via the address 192.168.59.103:1234. Everything works fine in OS X.

Now I have to test the Web stuff on IE which is why I have downloaded IE8, IE10 and so forth via Microsofts modern.IE website. As a result I have some more VirtualBox images, which are running Windows 7 and come with the propriate IE version.

The question is now how to access the Docker container in those Windows instances to test it under several IE versions.

What I have done so far:

Idea 1

To access the Django application I have looked up my local IP address and tried to access it via NAT in the Windows guests. Given my local IP adress 192.168.178.24, I have tried to access 192.168.178.24:1234 from Windows. Although I can ping 192.168.178.24 from Windows, I do get only a timeout on the port 1234.

Idea 2

Boot2docker runs a VirtualBox machine called boot2docker-vm. It comes with two network adapters, NAT and a host-only adapter called vboxnet0. The latter has the address 192.168.59.3 (which is the one which boot2docker ip returns) with the network mask 255.255.255.0. It runs a DHCP-Server on Server Adress 192.168.59.99 which gives addresses from 192.168.59.103-254.

I have added a second network adapter for my Windows guest systems which can also access via a host-only adapter the network vboxnet0. When being connected to the network the Windows machines do get a valid IP and can ping the IP 192.168.59.103. But I cannot connect to my Django instance on port 1234. If I try to call 192.168.59.103:1234 within Windows, I get a timeout.

Why is it not possible to connect to the Django instance? Can you help me? Thanks in advance.


Solution

  • I have found a solution to my problem here. To get access to the Django instance I had to open the port on the boot2docker-vm machine.

    This can be done by either by boot2docker-vm → settings → Network → Adapter 1 (NAT) → Port Forwarding and add a new rule where Host IPand Guest IP can be left empty and Host Port and Guest Port should be set to 1234.

    Another way to do so is executing the following command in the command line

    VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port1234,tcp,,1234,,1234";
    

    Of course this needs to be done for all ports, if more than one port is being used.