Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env bash
list=( $(docker-machine ls | grep Running | awk '{ print $1 }') )
for i in "${list[@]}"; do
ip=$(docker-machine ip $i)
#remove line matching ip
sudo sed -i '' '/'$ip'/d' /etc/hosts
#insert ip/host on last line
sudo sed -i -e '$a\
'"$ip"' '"$i"'' /etc/hosts
done
@brandonsimpson

This comment has been minimized.

Copy link

@brandonsimpson brandonsimpson commented Oct 26, 2015

FYI this also removes any other lines in the /etc/hosts file that were pointing to the same ip for any other host names other than the docker machine's name.

@cookandy

This comment has been minimized.

Copy link
Owner Author

@cookandy cookandy commented Oct 27, 2015

Yes, you are correct. Some additional logic could be added to search for host+ip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment