Docker Community Forums

Share and learn in the Docker community.

Network access to host machine from within Docker container


(Jochen Schalanda) #1

Hi,

I wonder how I can allow network access to the host machine (in my case Mac OS X 10.10.5) from within a Docker container running in a boot2docker VM (created via docker-machine) on VirtualBox 5.0.8.

Accessing the Docker containers from the host system is working but the other way round isn’t.

$ docker -v
Docker version 1.9.1, build a34a1d5
$ docker-machine -v
docker-machine version 0.5.1 (HEAD)
$ VBoxManage -v
5.0.8r103449

$ docker-machine ip default
192.168.99.100

$ docker port 7e37d2abdda7
9200/tcp -> 0.0.0.0:9200
9300/tcp -> 0.0.0.0:9300

$ curl 192.168.99.100:9200
{
  "status" : 200,
  "name" : "Bereet",
  "cluster_name" : "graylog",
  "version" : {
    "number" : "1.7.3",
    "build_hash" : "05d4530971ef0ea46d0f4fa6ee64dbc8df659682",
    "build_timestamp" : "2015-10-15T09:14:17Z",
    "build_snapshot" : false,
    "lucene_version" : "4.10.4"
  },
  "tagline" : "You Know, for Search"
}

$ ifconfig vboxnet0
vboxnet0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1500
	ether 0a:00:27:00:00:00
	inet 192.168.99.1 netmask 0xffffff00 broadcast 192.168.99.255

$ docker exec -it 7e37d2abdda7 ping -c 1 -w 1 192.168.99.1
PING 192.168.99.1 (192.168.99.1): 56 data bytes
--- 192.168.99.1 ping statistics ---
1 packets transmitted, 0 packets received, 100% packet loss

(Jeff Anderson) #2

There are three major strategies for getting this done:

  • Virtualbox port forwarding on the NAT interface. Manually open virtualbox and set up the port forwards on the NAT interface. from the VM’s point of view, the traffic will originate from the IP of the gateway on the eth0 network interface
  • Set up some sort of port forward process or firewall rule on your mac. listen on some port and then forward the traffic to the host-only IP.
  • Add a third network interface to the virtualbox machine. Set that interface to bridge mode. The VM will then be able to get a DHCP lease on the same network where your osx workstation is connected. You can check on the IP of eth2 manually when you docker-machine ssh in to the VM. That IP will be accessible on the network. (Requires you to shut down the VM to add the third network interface)

/Jeff


(Mark Petrovic) #3

What the OP is attempting works for me without additional NAT rules (that I am aware of):

$ docker -v
Docker version 1.10.3, build 20f81dd

$ VBoxManage -v
5.0.18r106667

$ docker-machine -v
docker-machine version 0.6.0, build e27fb87

$ docker exec -it 81 ping -c 1 -w 1 192.168.99.1
PING 192.168.99.1 (192.168.99.1) 56(84) bytes of data.
64 bytes from 192.168.99.1: icmp_seq=1 ttl=63 time=0.224 ms

--- 192.168.99.1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.224/0.224/0.224/0.000 ms

Naturally, I wonder why it works for me, but not OP.