This is how you can autorun boot2docker
on boot, so that you can use docker
as you would on Linux, without ever* knowing that the daemon's not running locally.
- Install VirtualBox &
boot2docker
(obviously) - Create a startup script with Automator
- Put in
/usr/local/bin/boot2docker up && /usr/local/bin/boot2docker shellinit > ~/.boot2docker-shellinit.sh
- Add
echo "export DOCKER_IP=$(boot2docker ip 2>/dev/null)" >> ~/.boot2docker-shellinit.sh
if you want the non-standard but very-convenientDOCKER_IP
env-var as well (thanks for the suggestion @city41!) - Update your
.profile
or equivalent file withsource ~/.boot2docker-shellinit.sh
- Reboot your machine
- Type
$ docker ps
into a terminal - ???
- PROFIT from a native-Linux-like Docker experience
One caveat: if the env vars change from their previous values (usually they don't) and you're quick enough to open your terminal before the Automator task finishes (usually you aren't), your shell will get stale env vars. In that case just wait a few seconds more and open a new terminal.
*) I lied a bit: Any ports you expose still won't be exposed on localhost, but instead at $DOCKER_HOST
. Also, only shares from /Users
work automagically, anything else you have to share manually with VirtualBox. Oh well, close enough.
I also added this to my .bashrc so I can grab the host's IP address, as DOCKER_HOST I find is not that useful:
export DOCKER_IP=$(boot2docker ip 2>/dev/null)