Having to remeber what the boot2docker ip address sucks, wouldn't it be better to access it like localhost?
First you need to get the boot2docker ip address. You can get that in terminal:
$ boot2docker ip
On my computer I get:
The VM's Host only interface IP address is: 192.168.59.103
So I'll add 192.168.59.103
to /private/etc/hosts
$ sudo vim /private/etc/hosts
My hosts
file looks like this now:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
192.168.59.103 localdocker
Save it!
Some browsers (ahem Chrome ahem) won't play nicely if you don't prepend an http://
or https://
to localdocker. So if you have a docker image running on :80
like I do then you can hit up http://localdocker:80
in your browsee, or you can curl the image with curl localdocker
.
The boot2docker ip address is not guaranteed to be static. It may change! You can just update the hosts file when that happens. Having said that, my ip has been static since I've been using this.