ryanzec
ryanzec

Reputation: 28040

How to connect to Docker instance from a different VM

I have docker running on my Mac with boot2docker in a VirtualBox VM. I then added into my hosts file on my Mac:

127.0.0.1 nginx

And on my Mac I can connect http://nginx in the browser and it load the website that is in the docker container. I also have a Windows VM running in VMWare Fusion in order to test IE. On my Windows VM, I have my hosts file configured to:

10.10.123.3 nginx

10.10.123.3 in the IP address of my mac however when I go to http://nginx in my browser on the window machine, it does not load. I have the network adapter set to "Internet Sharing -> Share with my Mac". I also have a simple http server running through python on port 8000 and I when I go to http://nginx:8000 it does load that site so it seems like my network configuration and window host file configure are working, just not for the docker stuff.

Is there something special I have to do to be able to expose the docker stuff to my window VM?

Upvotes: 1

Views: 1592

Answers (2)

Paul
Paul

Reputation: 26

I think you will want to run

boot2docker ip

To get the ip address of the boot2docker oracle virtual box. If you started the docker container with -p like:

docker start -p 8000:8000 `imagename`

Then use http://IpAddressOfOracleVirtBox:8000 if you did not use -p then no ports from the container will be exposed. The first 8000 is the port on the Virtual Box .. the second 8000 is the port of the container. You can do a -p 80:8000 if you want port 80 from virt to forward requests to 8000 in the container.

Answer (edit by question author)

After using boot2docker ip, all you have to do it use that IP address instead of the Mac's IP address in the Window's VM hosts file.

Upvotes: 1

Rui Andrada
Rui Andrada

Reputation: 246

I guess you not able to access the machine because the network method "Internet Sharing -> Share with my Mac" only permits the VM to access internet through your Mac.

I think you have to create another network in your VM, bridge mode or internal network.

The network method you using only permits the VM to access internet, not other addresses in your network.

I guess bridge mode is more easy because the VM will got a ip address from your router network.

I don't have a Mac to test here, but I guess that is the problem you have.

I hope helps you.

Upvotes: 0

Related Questions