Using Docker on a Mac with Boot2Docker

UPDATE 2016-11-12: This post is no longer relevant now that Docker for Mac.

One thing to remember

When your running boot2docker on a Mac (and probably Windows as well) it’s important to remember that ports exposed by your containers will not be directly accessible via localhost as you might expect. Since docker is running within boot2docker containers will be exposed via ports on the boot2docker IP.

For example, if running docker ps tells you your app is exposing port 80 on some high-numbered port on the local host, it is actually exposed via boot2dockers IP:

$ docker ps
6751b94bb5c0 ubuntu:latest>80/tcp

Going to in your browser won’t work. You need to replace with boot2docker’s IP address. To find it, run:

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

Putting that into the browser will along with the correct port will give you and you will be able to access your web app as expected.

This may all be very simple for anyone familiar with networking, but it took me a good amount of time to figure this out with no error message. I guess you should just run Docker on Linux 😉

Although not entirely related, I wrote a gist to automatically export boot2docker’s IP address into an environment variable whenever it is set: