Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save andrewvmail/dcb090b3ceace8e4c2fe0046a06c574f to your computer and use it in GitHub Desktop.

Select an option

Save andrewvmail/dcb090b3ceace8e4c2fe0046a06c574f to your computer and use it in GitHub Desktop.
Use native virtualization on OS X docker with xhyve
eval "$(docker-machine env default)"
update-docker-host(){
# clear existing docker.local entry from /etc/hosts
sudo sed -i '' '/[[:space:]]docker\.local$/d' /etc/hosts
# get ip of running machine
export DOCKER_IP="$(echo ${DOCKER_HOST} | grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}')"
# update /etc/hosts with docker machine ip
[[ -n $DOCKER_IP ]] && sudo /bin/bash -c "echo \"${DOCKER_IP} docker.local\" >> /etc/hosts"
}
update-docker-host
emulate sh -c '. ~/.profile'
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>EnvironmentVariables</key>
<dict>
<key>PATH</key>
<string>{{user-path}}</string>
</dict>
<key>Label</key>
<string>com.docker.machine.default</string>
<key>ProgramArguments</key>
<array>
<string>{{docker-machine}}</string>
<string>start</string>
<string>default</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
#!/usr/bin/env sh
setup_shell() {
mv ~/.profile{,.backup}
cp ./.profile ~/.profile
if [[ $SHELL == *"zsh"* ]]
then
mv ~/.zprofile{,.backup}
cp ./.zprofile ~/.zprofile
fi
}
setup_docker_machine() {
mkdir -p ~/Library/LaunchAgents
cp ./com.docker.machine.default.plist ~/Library/LaunchAgents/com.docker.machine.default.plist
}
install() {
setup_shell
setup_docker_machine
}
uninstall() {
rm ~/.profile
mv ~/.profile{.backup,}
if [[ $SHELL == *"zsh"* ]]
then
rm ~/.zprofile
mv ~/.zprofile{.backup,}
fi
rm ~/Library/LaunchAgents/com.docker.machine.default.plist
}
case "$1" in
install)
install
;;
uninstall)
uninstall
;;
*)
echo $"Usage: $0 {install|uninstall}"
exit 1
esac

Requirements

  • Docker Machine + Docker. Install Docker Toolbox
  • curl
  • A Virtualbox-driven Docker Machine called "default" docker-machine create --driver virtualbox default (this is the default with Docker toolkit).

Usage

The git.io URL (http://git.io/vsk46) is a shortened form of the raw url of the plist.

$ curl -sL http://git.io/vsk46 | \
    sed -e "s?{{docker-machine}}?$(which docker-machine)?" \
        -e "s?{{user-path}}?$(echo $PATH)?" \
    >~/Library/LaunchAgents/com.docker.machine.default.plist && \
    launchctl load ~/Library/LaunchAgents/com.docker.machine.default.plist

Credits

Based on this

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