Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jcarley/3be3478b19f933291e6f to your computer and use it in GitHub Desktop.
Save jcarley/3be3478b19f933291e6f to your computer and use it in GitHub Desktop.
A basic shell script to use a configuration file to update local development hosts ip running on docker-machine (virtual box) and Mac OSX
#!/usr/bin/env bash
#Usage docker-machine-update-hosts.sh hosts.conf default
#arg1 is a configuration file with hosts
#arg2 is the docker-machine name e.g. default
DOCKER_IP=$(docker-machine ip $2)
echo "$2 ip: $DOCKER_IP"
#Remove existing lines from hosts
while IFS='' read -r line || [[ -n "$line" ]]; do
echo "Removing existing domain $line"
sudo sed -i '' '/'$line'/d' /etc/hosts
done < "$1"
#Add new hosts to the bottom of the file
while IFS='' read -r line || [[ -n "$line" ]]; do
echo "Adding entry $DOCKER_IP $line"
sudo echo "$DOCKER_IP $line" >>/etc/hosts
done < "$1"
example.dev
other-site.local
my-site.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment