Skip to content

Instantly share code, notes, and snippets.

@thogg4
Last active October 8, 2015 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thogg4/2130953fde46b5d32ac5 to your computer and use it in GitHub Desktop.
Save thogg4/2130953fde46b5d32ac5 to your computer and use it in GitHub Desktop.
name=${PWD##*/}
if docker-machine ls | grep -q "^$name\s" ; then
echo 'machine found'
else
echo 'machine not found. creating...'
docker-machine create --driver virtualbox $name
docker-machine ssh $name "sudo curl -o /var/lib/boot2docker/bootsync.sh https://gist.githubusercontent.com/thogg4/81de781d4a21382d1c11/raw/9b342537b42e1b7c595a9e1e112c2a131322fb51/bootsync.sh"
docker-machine restart $name
fi
echo 'setting up env'
eval "$(docker-machine env $name)"
ip=$(docker-machine ip $name)
hosts_count=$( grep -ic "$ip $name" /etc/hosts )
if [ $hosts_count -eq 0 ]; then
sudo sed -in "/$name/d" /etc/hosts
echo "setting ip address to $name in /etc/hosts"
sudo bash -c "echo '$ip $name' >> /etc/hosts"
echo "ip written to hosts file"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment