Skip to content

Instantly share code, notes, and snippets.

@devster
Created December 11, 2014 15:18
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 devster/028f4133937a2301e0e7 to your computer and use it in GitHub Desktop.
Save devster/028f4133937a2301e0e7 to your computer and use it in GitHub Desktop.
#!/bin/sh
set -e
IP=`sudo docker inspect -f '{{ .NetworkSettings.IPAddress }}' ${1}`
HOST=$2
[ -z "$HOST" ] && exit 1;
sudo sed -i "s/.*\s${HOST}$/${IP} ${HOST}/" /etc/hosts
grep -P "\s${HOST}$" /etc/hosts > /dev/null || sudo -- sh -c "echo \"${IP} ${HOST}\" >> /etc/hosts"
grep -P "^${IP} ${HOST}$" /etc/hosts > /dev/null
if [ $? -eq 0 ]; then
echo "Set host: ${IP} ${HOST}"
else
echo "Fail to update the host file with: ${IP} ${HOST}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment