Created
January 27, 2016 17:38
-
-
Save koemeet/925fa2a28a0c73598124 to your computer and use it in GitHub Desktop.
Setup Mac OSX to use vagrant + docker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DOCKER_VERSION=1.9.0 | |
DOCKER_COMPOSE_VERSION=1.5.0 | |
# Console colors | |
red='\033[0;31m' | |
green='\033[0;32m' | |
yellow='\033[1;33m' | |
NC='\033[0m' | |
# Homebrew installation | |
echo -e "${green}Installing Homebrew...${NC}" | |
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" | |
# Cask installation | |
echo -e "${green}Installing Cask...${NC}" | |
brew install caskroom/cask/brew-cask | |
# Update brew formulae | |
echo -e "${green}Updating brew formulae...${NC}" | |
brew update | |
# VirtualBox installation | |
echo -e "${green}Installing virtualbox...${NC}" | |
brew cask install virtualbox | |
# Kill the default adapter and DHCP server to avoid network issues down the road | |
VBoxManage dhcpserver remove --netname HostInterfaceNetworking-vboxnet0 | |
VBoxManage hostonlyif remove vboxnet0 | |
# Vagrant installation | |
echo -e "${green}Installing vagrant...${NC}" | |
brew cask install vagrant | |
# Install docker | |
echo -e "${green}Installing docker...${NC}" | |
sudo curl -sSL "https://get.docker.com/builds/$(uname -s)/$(uname -m)/docker-$DOCKER_VERSION" -o /usr/local/bin/docker | |
sudo chmod +x /usr/local/bin/docker | |
# Install docker-compose | |
echo -e "${green}Installing docker-compose...${NC}" | |
sudo curl -sSL "https://github.com/docker/compose/releases/download/$DOCKER_COMPOSE_VERSION/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | |
sudo chmod +x /usr/local/bin/docker-compose | |
# Docker Host IP | |
DOCKER_HOST_IP='192.168.10.10' | |
# Write DOCKER_HOST variable export to a matching .rc file based on the shell (bash or zsh) | |
SOURCE_FILE='' | |
DOCKER_HOST_EXPORT="\n# Docker (default for Vagrant based boxes)\nexport DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375\n" | |
# Detect shell to write to the right .rc file | |
if [[ $SHELL == '/bin/bash' || $SHELL == '/bin/sh' ]]; then SOURCE_FILE=".bash_profile"; fi | |
if [[ $SHELL == '/bin/zsh' ]]; then SOURCE_FILE=".zshrc"; fi | |
if [[ $SOURCE_FILE ]]; then | |
# See if we already did this and skip if so | |
grep -q "export DOCKER_HOST=tcp://${DOCKER_HOST_IP}:2375" $HOME/$SOURCE_FILE | |
if [[ $? -ne 0 ]]; then | |
echo -e "${green}Adding automatic DOCKER_HOST export to $HOME/$SOURCE_FILE${NC}" | |
echo -e $DOCKER_HOST_EXPORT >> $HOME/$SOURCE_FILE | |
fi | |
else | |
echo -e "${red}Cannot detect your shell. Please manually add the following to your respective .rc or .profile file:${NC}" | |
echo -e "$DOCKER_HOST_EXPORT" | |
fi | |
if [[ $B2D_NO_AUTOSTART == '' ]]; then | |
# Start the boot2docker VM | |
echo -e "${green}Starting the boot2docker VM...${NC}" | |
vagrant up | |
# Check that Docker works | |
echo -e "${green}Checking that everything is in place...${NC}" | |
docker version && vagrant ssh -c 'docker-compose --version' | |
if [[ $? -ne 0 ]]; then | |
echo -e "${red}Something went wrong. Please review console output for possible clues.${NC}" | |
exit 1 | |
else | |
echo -e "${green}Docker Host is up and running. Please restart your shell.${NC}" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment