Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Transparent boot2docker on OS X for a native-Linux-like Docker experience

Transparent boot2docker on OS X

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.

  1. Install VirtualBox & boot2docker (obviously)
  2. Create a startup script with Automator
  3. Put in /usr/local/bin/boot2docker up && /usr/local/bin/boot2docker shellinit > ~/.boot2docker-shellinit.sh
  4. Add echo "export DOCKER_IP=$(boot2docker ip 2>/dev/null)" >> ~/.boot2docker-shellinit.sh if you want the non-standard but very-convenient DOCKER_IP env-var as well (thanks for the suggestion @city41!)
  5. Update your .profile or equivalent file with source ~/.boot2docker-shellinit.sh
  6. Reboot your machine
  7. Type $ docker ps into a terminal
  8. ???
  9. 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.

@city41

This comment has been minimized.

Copy link

@city41 city41 commented Dec 29, 2014

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)

@willdurand

This comment has been minimized.

Copy link

@willdurand willdurand commented Jan 2, 2015

It does not really work like "on Linux" because you can only mount volumes from /Users on your Mac, so for instance, mounting the host folder /tmp will not work :-)

@jareware

This comment has been minimized.

Copy link
Owner Author

@jareware jareware commented Jan 5, 2015

@city41, great point!

@willdurand, you're right, I lied a bit. :) You can mount /tmp too, though, you just have to do it by hand with the boot2docker VM, and then do it again every time it updates. :>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.