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

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

To install:

$ sh -c "$(curl -fsSL https://gist.githubusercontent.com/astrohckr/0d5303b787a449cd564f/raw/install.sh)"

To uninstall:

$ sh -c "$(curl -fsSL https://gist.githubusercontent.com/astrohckr/0d5303b787a449cd564f/raw/uninstall.sh)"

Credits

Based on this

<?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>
GIST_URL='https://gist.githubusercontent.com/astrohckr/0d5303b787a449cd564f/raw'
setup_shell() {
[ -f ~/.profile ] && \
mv ~/.profile{,.backup} && \
echo "Created backup of existing ~/.profile to ~/.profile.backup"
curl -o $GIST_URL/profile ~/.profile && echo "Setup $SHELL"
if [[ $SHELL == *"zsh"* ]];
then
[ -f ~/.zprofile ] && mv ~/.zprofile{,.backup}
curl -o $GIST_URL/zprofile ~/.zprofile
fi
}
setup_docker_machine() {
mkdir -p ~/Library/LaunchAgents
curl -o $GIST_URL/com.docker.machine.default.plist ~/Library/LaunchAgents/com.docker.machine.default.plist && \
echo "Setup docker-machine to launch on startup"
}
setup_shell
setup_docker_machine
echo "Now, reboot."
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
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
}
remove_docker_machine_setup() {
rm ~/Library/LaunchAgents/com.docker.machine.default.plist && \
echo "Removed docker-machine from startup"
}
remove_shell_setup
remove_docker_machine_setup
echo "Removed all the things."
emulate sh -c '. ~/.profile'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment