Boot2Docker lets you run Docker Containers on your Mac by using VirtualBox to create a stripped down Linux Box (call that DH) where the Docker daemon can run. DH and your Mac have a networking interface on a software defined network (named vboxnet) created by Virtual Box. The containers and DH have networking interfaces on a software defined network created by the Docker daemon. Call it SDN-D, since they didn’t name it.
The authors of boot2docker did not set things up so your Mac to you connect directly to the containers on sdn-d. Presumably they didn’t think it wise to adjust the Mac routing tables. But you can. This is very convenient. It lets you avoid most of the elegant, but tedious, -publish or -publish-all (aka -p, -P) switches when running a container. They hand-craft special plumbing for ports when running with containers. It also nice because DH is very stripped down making it painful to work on.
So, I give you this little shell script: establish-routing-to-boot2docker-container-network. It adds routing on the Mac to SDN-D via DH on vboxnet. This is risky if SDN-D happens to overlap a network that the Mac is already routing to, and the script does not guard against that. See bellow for how to deal if you have that problem.
If your containers have ssh listeners then you can put this in your ~/.ssh/config to avoid the PIA around host keys. But notice how it hardwires the numbers for SDN-D.
Host 172.17.0.* StrictHostKeyChecking no UserKnownHostsFile /dev/null User root
The numbers of SDN-D are bound when the Docker daemon launches on DH. The –bip switch, used when the docker daemon launches, can adjusts that. You setting it in /var/lib/boot2docker/profile on DH via EXTRA_ARGS. Do that if you have the overlap problem mentioned above. I do it because I want SDN-D to be small. That let’s nmap can scan it quickly.
If you’ve not used ~/.ssh/config before, well you should! But in that case you may find it useful to know that ssh uses the first setting it finds that Host block should appear before your global defaults.