UPDATE 2016-11-12: This post is no longer relevant now that Docker for Mac.
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:
0.0.0.0:49154 in your browser won’t work. You need to replace
0.0.0.0 with boot2docker’s IP address. To find it, run:
Putting that into the browser will along with the correct port will give you
192.168.55.555:49154 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: