Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save newlc/6893b8608f873e7f7e36f22c174505e8 to your computer and use it in GitHub Desktop.

Select an option

Save newlc/6893b8608f873e7f7e36f22c174505e8 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() {
[ -f ~/.profile ] && \
mv ~/.profile{,.backup} && \
echo "Created backup of existing ~/.profile to ~/.profile.backup"
cp ./.profile ~/.profile && echo "Setup $SHELL"
if [[ $SHELL == *"zsh"* ]];
then
[ -f ~/.zprofile ] && mv ~/.zprofile{,.backup}
cp ./.zprofile ~/.zprofile
fi
}
remove_shell_setup() {
rm ~/.profile
[ -f ~/.profile.backup ] && \
mv ~/.profile{.backup,} && \
echo "Restored ~/.profile.backup to ~/.profile"
if [[ $SHELL == *"zsh"* ]]
then
rm ~/.zprofile
[ -f ~/.zprofile.backup ] && mv ~/.zprofile{.backup,}
fi
}
setup_docker_machine() {
mkdir -p ~/Library/LaunchAgents
cp ./com.docker.machine.default.plist ~/Library/LaunchAgents/com.docker.machine.default.plist && \
echo "Setup docker-machine to launch on startup"
}
remove_docker_machine_setup() {
rm ~/Library/LaunchAgents/com.docker.machine.default.plist && \
echo "Removed docker-machine from startup"
}
install() {
setup_shell
setup_docker_machine
echo "Now reboot."
}
uninstall() {
remove_shell_setup
remove_docker_machine_setup
}
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