Skip to content

Instantly share code, notes, and snippets.

@dimitrovs
Last active September 17, 2017 20:36
Show Gist options
  • Save dimitrovs/493678fd86c7cdf0c88312d9ddb4906b to your computer and use it in GitHub Desktop.
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.
#!/bin/bash
if [[ -z $(grep dockerhost /etc/hosts) ]]
then
echo `/sbin/ip route|awk '/default/ { print $3 }'` dockerhost >> /etc/hosts
fi
@gavvvr
Copy link

gavvvr commented Sep 17, 2017

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