Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gregorynicholas/a1c8cb522d1629ddbbe89a124b317384 to your computer and use it in GitHub Desktop.
Save gregorynicholas/a1c8cb522d1629ddbbe89a124b317384 to your computer and use it in GitHub Desktop.
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment