Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Use native virtualization on OS X docker with xhyve

What this?

So one of the painful points of using docker on OS X is that you need to run a virtualbox VM, which often suffers from performance issues. With xhyve, a OS X virtualization system, and docker-machine-xhyve you can now have docker use the native OS X hypervisor to run containers.

No more dealing with virtualbox shenanigans!

In this script, I've also set up a way to autoconfigure terminal sessions to load docker's environment vars (dependent on docker-machine) so you do not have to run eval $(docker-machine env whatever) every time you open a new terminal window.


  • At least OS X 10.10 (Yosemite) because Hypervisor.framework, on which xhyve depends, was first introduced in Yosemite.
  • homebrew

Before you begin

Uninstall Docker Toolbox:

$ sh -c "$(curl -fsSl"

And remove existing caches

$ sudo rm -rf ~/.docker


To install:

$ sh -c "$(curl -fsSL"

To uninstall:

$ sh -c "$(curl -fsSL"

Known Issues / shenanigans to be aware of

  • After rebooting, when you open a Terminal / iTerm session, there will be an error regarding TLS certs. You will need to run docker-machine restart dev.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">
<plist version="1.0">
setup_shell() {
[ -f ~/.profile ] && \
mv ~/.profile{,.backup} && \
echo "Created backup of existing ~/.profile to ~/.profile.backup"
curl $GIST_URL/profile -o ~/.profile && echo "Setup $SHELL"
if [[ $SHELL == *"zsh"* ]];
[ -f ~/.zprofile ] && mv ~/.zprofile{,.backup}
curl $GIST_URL/zprofile -o ~/.zprofile
setup_docker_machine() {
## Prerequisites
echo 'Installing xhyve, docker, docker-compose, and go'
brew update
brew install xhyve docker go
brew install docker-compose --without-docker-machine --without-docker
## Set up Go
echo 'Setting up go directories'
mkdir ~/.go
## Set up shell
if [[ $SHELL == *"zsh"* ]]; then
echo 'export GOPATH=$HOME/.go' >> $shellrc
export GOPATH=$HOME/.go
## Install docker-machine
go get
cd $GOPATH/src/
make build
make install
## Install docker-machine xhyve
go get -u
cd $GOPATH/src/
make build
make install
sudo chown root:wheel $GOPATH/bin/docker-machine-driver-xhyve
sudo chmod u+s $GOPATH/bin/docker-machine-driver-xhyve
## Create the xhyve machine
docker-machine create dev --driver xhyve --xhyve-experimental-nfs-share
mkdir -p ~/Library/LaunchAgents
curl $GIST_URL/ -o\
~/Library/LaunchAgents/ && \
echo "Setup docker-machine to launch on startup"
echo "Now, reboot."
if [[ $(pgrep docker-machine-driver-xhyve) ]]; then
if [[ $(docker-machine status dev) == *"Running"* ]]; then
eval $(docker-machine env dev)
echo "It looks like docker-machine did not start correctly :("
echo "docker-machine dev is not running"
echo "try running: docker-machine start dev"
remove_shell_setup() {
rm ~/.profile
[ -f ~/.profile.backup ] && \
mv ~/.profile{.backup,} && \
echo "Restored ~/.profile.backup to ~/.profile"
if [[ $SHELL == *"zsh"* ]]
rm ~/.zprofile
[ -f ~/.zprofile.backup ] && mv ~/.zprofile{.backup,}
remove_docker_machine_setup() {
rm ~/Library/LaunchAgents/ && \
echo "Removed docker-machine from startup"
echo "Removed all the things."
emulate sh -c '. ~/.profile'

This comment has been minimized.

Copy link

commented Feb 2, 2016

Wow great fork. Thanks man!!!!!!!!


This comment has been minimized.

Copy link

commented May 14, 2019

need some update?

brew install  --without-docker-machine --without-docker docker-compose
Usage: brew install [options] formula

Install formula.

formula is usually the name of the formula to install, but it can be specified
in several different ways.

Unless HOMEBREW_NO_INSTALL_CLEANUP is set, brew cleanup will be run for the
installed formulae or, every 30 days, for all formulae.

    -d, --debug                      If brewing fails, open an interactive
                                     debugging session with access to IRB or a
                                     shell inside the temporary build directory
        --env                        If std is passed, use the standard build
                                     environment instead of superenv.If super
                                     is passed, use superenv even if the formula
                                     specifies the standard build environment.
        --ignore-dependencies        An unsupported Homebrew development flag to
                                     skip installing any dependencies of any
                                     kind. If the dependencies are not already
                                     present, the formula will have issues. If
                                     you're not developing Homebrew, consider
                                     adjusting your PATH rather than using this
        --only-dependencies          Install the dependencies with specified
                                     options but do not install the specified
        --cc                         Attempt to compile using provided
                                     compiler. compiler should be the name
                                     of the compiler's executable, for instance
                                     gcc-7 for GCC 7. In order to use LLVM's
                                     clang, use llvm_clang. To specify the
                                     Apple-provided clang, use clang. This
                                     parameter will only accept compilers that
                                     are provided by Homebrew or bundled with
                                     macOS. Please do not file issues if you
                                     encounter errors while using this flag.
    -s, --build-from-source          Compile the specified formula from source
                                     even if a bottle is provided. Dependencies
                                     will still be installed from bottles if
                                     they are available.
        --force-bottle               Install from a bottle if it exists for the
                                     current or newest version of macOS, even if
                                     it would not normally be used for
        --include-test               Install testing dependencies required to
                                     run brew test.
        --devel                      If formula defines it, install the
                                     development version.
        --HEAD                       If formula defines it, install the HEAD
                                     version, aka. master, trunk, unstable.
        --fetch-HEAD                 Fetch the upstream repository to detect if
                                     the HEAD installation of the formula is
                                     outdated. Otherwise, the repository's HEAD
                                     will be checked for updates when a new
                                     stable or development version has been
        --keep-tmp                   Don't delete the temporary files created
                                     during installation.
        --build-bottle               Prepare the formula for eventual bottling
                                     during installation.
        --bottle-arch                Optimise bottles for the given architecture
                                     rather than the oldest architecture
                                     supported by the version of macOS the
                                     bottles are built on.
    -f, --force                      Install without checking for previously
                                     installed keg-only or non-migrated
    -v, --verbose                    Print the verification and postinstall
        --display-times              Print install times for each formula at the
                                     end of the run.
    -i, --interactive                Download and patch formula, then open a
                                     shell. This allows the user to run
                                     ./configure --help and otherwise
                                     determine how to turn the software package
                                     into a Homebrew package.
    -g, --git                        Create a Git repository, useful for
                                     creating patches to the software.
    -h, --help                       Show this message.
**Error: invalid option: --without-docker-machine**

This comment has been minimized.

Copy link

commented May 14, 2019
As of 2 February 2019, Homebrew no longer supports options link.

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.