Last active
September 17, 2017 20:36
-
-
Save dimitrovs/493678fd86c7cdf0c88312d9ddb4906b to your computer and use it in GitHub Desktop.
Add the IP of a dockerhost to the /etc/hosts file of a Docker container if not already there.
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 | |
if [[ -z $(grep dockerhost /etc/hosts) ]] | |
then | |
echo `/sbin/ip route|awk '/default/ { print $3 }'` dockerhost >> /etc/hosts | |
fi |
@sburnwal but docker host is the gateway, isn't it? In what kind of config is docker host not the gateway of docker containers?
Note that if your host is Mac, the 172.17.0.1
will be a wrong answer. Use dedicated DNS name docker.for.mac.localhost
instead.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gives the gateway ip and not the docker host ip.