Created
April 9, 2016 22:07
-
-
Save rkuzsma/2a41b276a8d9e64acb978cc539f43457 to your computer and use it in GitHub Desktop.
Add (or replace) an entry called "dockermachine" in /etc/hosts that points to your local "docker-machine ip" so you can use http://dockermachine/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Add (or replace) an entry called "dockermachine" in /etc/hosts that points to | |
# your local "docker-machine ip" so you can use http://dockermachine/ | |
eval $(docker-machine env) | |
readonly DOCKER_HOST_NAME="dockermachine" | |
readonly HOSTS_FILE="/etc/hosts" | |
readonly TMPFILE=$(mktemp) | |
readonly DOCKER_HOST_IP=$(docker-machine ip) | |
readonly DOCKER_HOST_ENTRY="$DOCKER_HOST_IP $DOCKER_HOST_NAME" | |
echo "Adding '$DOCKER_HOST_IP $DOCKER_HOST_NAME' entry to '$HOSTS_FILE' so you can use http://$DOCKER_HOST_NAME URLs for testing" | |
if grep -q "^[^#]*$DOCKER_HOST_NAME" "$HOSTS_FILE" ; then | |
echo "Replacing existing '$DOCKER_HOST_NAME' entry." | |
awk "!/^[^#].*$DOCKER_HOST_NAME/ {print \$0}" "$HOSTS_FILE" > "$TMPFILE" | |
else | |
cp $HOSTS_FILE $TMPFILE | |
fi | |
echo -e "$DOCKER_HOST_ENTRY" >> "$TMPFILE" | |
echo "Modifying $HOSTS_FILE requires sudo privileges, please enter your password." | |
sudo -k sh -c "cat \"$TMPFILE\" > \"$HOSTS_FILE\"" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment