Accessing docker containers from your mac

The most prevalent solution for running docker on the mac is using boot2docker or maybe a CoreOS vagrant VM. In either case the docker0 network is not accessible in the mac since the it is created as a host only network on Virtual Box, usually with the CIDR of

A simple way to get connectivity to the host only network created for docker is to add a route for the docker’s network CIDR with the gateway of the VM’s IP

  1. Find the IP of your VM, if you are using docker machine then: $: docker-machine ls
  2. Find the CIDR for you docker private network
    • $: docker-machine ssh yourVmName
    • $: ifconfig docker0 | grep "inet addr" if the netmask is that means it is a /16 network so if the gateway is its CIDR would be
  3. Create a route for docker0 network: $: sudo route -n add

To confirm that the route was added successfuly you can check the route table entries with netstat, you should see something like this:

netstat -nr
172.17        UGSc            1        4 vboxnet