Created
April 7, 2017 08:08
-
-
Save am-/922bc089f4848f33b301e9c320f3bc90 to your computer and use it in GitHub Desktop.
Dynamically determine the IP address of a Docker container and change the /etc/hosts accordingly
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/sh | |
# Assumption 1: $CONTAINER and $HOST are properly set | |
# Assumption 2: The host is already set in /etc/hosts. | |
# Assumption 3: In /etc/hosts, the IP address and host are separated by a tab | |
IP=`docker exec -t $CONTAINER ip addr | grep -oE "\b([0-9]{1,3}\.){3}[0-9]{1,3}\b" | grep 172` | |
sudo sed -i "/$HOST/s/[^\t]*/$IP/" /etc/hosts |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment