Skip to content

Instantly share code, notes, and snippets.

@whitekid
Last active August 29, 2015 14:21
Show Gist options
  • Save whitekid/ea78bb56d5bd901187dc to your computer and use it in GitHub Desktop.
Save whitekid/ea78bb56d5bd901187dc to your computer and use it in GitHub Desktop.
automatically update boot2docker ip in /etc/hosts
#!/bin/bash
# Usage:
# git clone https://gist.github.com/ea78bb56d5bd901187dc.git docker.gist
# mkdir ~/bin
# ln -s docker.gist/docker.sh ~/bin/docker
# export PATH=$PATH:~/bin
/usr/local/bin/docker "$@"
r=$?
update_boot2docker_ip() {
IP=`boot2docker ip`
if grep -q 'boot2docker$' /etc/hosts; then
sudo sed -i '' -E "s/^[0-9\.]+ boot2docker$/${IP/./\\.} boot2docker/" /etc/hosts
else
sudo sh -c "echo '${IP} boot2docker' >> /etc/hosts"
fi
}
if [ $r == "0" ]; then
update_boot2docker_ip
fi
exit $r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment