I have run the following command to forward sinatra and redis ports to my docker instance running in virtualbox on OSX:
ports=( 4567 6379 )
for port in "${ports[@]}"
do
echo "Forwarding $port"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcpport$port,tcp,,$port,,$port"
done
However, periodically (like every 60 seconds) requests to either of these docker instances over my machine's public IP, originating from my machine, will hang for 40-60 seconds. However, my docker instance is healthy and I can connect directly via 192.168.59.103.
Thus, why would a connection such as:
redis-cli -h 192.168.1.1 PING
Periodically hang, but
redis-cli -h 192.168.59.103 PING
Always work? Is there some kind of bug in VirtualBox or boot2docker?
Moreover, during the periods where these requests hang, I have noticed that calls to
boot2docker ip
and
boot2docker ssh
Themselves both hang. I am running boot2docker 1.6.2 and VirtualBox 4.3.28 on OSX 10.10.3.
Additional debugging reveals that inter-instance connectivity is now impaired as well. I have linked two containers, and periodically HTTP requests between them will hang. I went so far as to run telnet container_name 4567
, then I typed
GET /
Which, of course, is the most basic way to test a webserver. From inside of container_name, I ran curl http://localhost:4567/
. The telnet request hung, but the curl http://localhost:4567/
returned immediately.
This is one of the main reasons we added the extra localhost only interface (192.168.59.103
) - the virtual box bat port forwarding is woeful and very unreliable.