[This post explores troubleshooting network issues you might find when using docker with boot2docker, and in doing so illustrates the network topology of services running inside of docker and a VM host like VirtualBox]

Docker is an amazing project, offering to remove the burden of managing servers when you want to play with a technology stack, and offering to remove the burden of deploying those stacks into production when you are ready to launch your new venture into the world. I love the promise of Docker because it allows me to easily handle installation of an entire technology stack (using the docker registry which is a store of docker images, bundles of software components that others have configured and published for use by anyone) and then quickly deploy that exact configuration onto scalable Iaas providers like Digital Ocean or AWS. Instead of trying to figure out how to install a new mysterious Java service like Mesos and make sure I have all the necessary components and configured (a real painful issue unless you are a Java expert) I can run command like this:

1
2
3
4
5
$ docker search mesos
NAME                                   DESCRIPTION    STARS     OFFICIAL   AUTOMATED
redjack/mesos-master                                  3                    [OK]
...
$ docker run -P redjack/mesos-master

And, docker will pull a preconfigured image with all the necessary components, and run it inside a docker container. Then, you can run a command

1
docker ps
to retrieve the “exposed” port and access the Mesos control panel on your laptop.

1
2
3
$ docker ps
CONTAINER ID     ....     STATUS             PORTS                    NAMES
fcd04b12ed24     ....     Up 42 seconds      0.0.0.0:49153->5050/tcp   jovial_meitner 

This tells us that we can go to

1
http://localhost:49153/
to see the Mesos control panel. Specifically, that the Docker host system has mapped the default 5050 port on which Mesos listens inside the container to a random public port 49153. The
1
0.0.0.0
IP address is the “ANY” address, meaning you can use localhost or the IP of your Wi-Fi connection, or even 0.0.0.0 itself.

However, this did not work for me. None of these addresses worked correctly.

One note of clarification: Docker runs best on Linux itself, but you can easily play with Docker on OSX using the boot2docker tool. boot2docker installs a tiny host system (running as a VM on VirtualBox) which then integrates with the docker client and hosts your containers. boot2docker also creates a mapping of IP addresses internal to the host VM and to external adapters managed by the VirtualBox host. I’m using boot2docker here, and this is why I am having these issues.

To troubleshoot this problem, let’s look deeper into what is happening with our container. We can run a command called

1
docker inspect
to view the current state of any container; provide it with the name or ID of a container retrieved using the
1
docker ps
command. This command is a shortcut to all that (which works if you are running a single docker container):

1
2
$ docker inspect $(docker ps -q) | grep IPA
  "IPAddress": "172.17.0.9",

This tells us that the IP that our container is using is 172.17.0.9. Let’s see if we can ping this IP address from our OSX laptop.

1
2
3
4
5
$ ping 172.17.0.11
PING 172.17.0.11 (172.17.0.11): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
^C

No luck! But, if we jump inside our boot2docker system and try the same command:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
$ boot2docker ssh
Warning: Permanently added '[localhost]:2022' (RSA) to the list of
known hosts.
                        ##        .
                  ## ## ##       ==
               ## ## ## ##      ===
           /""""""""""""""""\___/ ===
      ~~~ {~~ ~~~~ ~~~ ~~~~ ~~ ~ /  ===- ~~~
           \______ o          __/
             \    \        __/
              \____\______/
 _                 _   ____     _            _
| |__   ___   ___ | |_|___ \ __| | ___   ___| | _____ _ __
| '_ \ / _ \ / _ \| __| __) / _` |/ _ \ / __| |/ / _ \ '__|
| |_) | (_) | (_) | |_ / __/ (_| | (_) | (__|   <  __/ |
|_.__/ \___/ \___/ \__|_____\__,_|\___/ \___|_|\_\___|_|
boot2docker: 1.0.0
             master : 16013ee - Mon Jun  9 16:33:25 UTC 2014
docker@boot2docker:~$ sudo su
root@boot2docker:/home/docker# ping 172.17.0.11
PING 172.17.0.11 (172.17.0.11): 56 data bytes
64 bytes from 172.17.0.11: seq=0 ttl=64 time=0.084 ms
^C

$ curl -I http://172.17.0.11:5050/
HTTP/1.1 200 OK
Date: Thu, 12 Jun 2014 03:59:51 GMT
Content-Length: 4614
Content-Type: text/html

docker@boot2docker:~$ curl -I http://localhost:49153/
HTTP/1.1 200 OK
Date: Thu, 12 Jun 2014 04:00:02 GMT
Content-Length: 4614
Content-Type: text/html    

In this case, we can ping the IP address successfully. The container is running properly and our docker host system can see the container IP, and we can see the service running off the host IP on the correct port and our host system successfully has forwarded the port to the localhost port 49153.

For some reason, our IP is not routable on our Mac laptop. boot2docker did not properly establish the routing between our VirtualBox system, our boot2docker host, and our OSX laptop. Advanced users could probably muck around and figure out what is wrong by looking into the network adapter configuration for VirtualBox, but we are using boot2docker because we wanted to ignore this minutiae. There is a simpler way, if you can tolerate your own ignorance (I’m good at this).

1
2
$ boot2docker ip
The VM's Host only interface IP address is: 192.168.59.103

We now know the IP address of the boot2docker host. If we use this with the port attached, we can now see Mesos running.

Successfully access Mesos

Whew! I’m glad this post is done. Running docker fries my battery.