Created
August 29, 2017 07:37
-
-
Save cdekok/8df671c859b7cc5aa6f44fb9e2ccf85b to your computer and use it in GitHub Desktop.
Docker reverse proxy for localhost dns
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
exists() | |
{ | |
command -v "$1" >/dev/null 2>&1 | |
} | |
if exists dnsmasq; then | |
echo 'Your system already has dnsmasq installed skipping install' | |
else | |
echo 'brew install dnsmasq' | |
brew install dnsmasq | |
fi | |
TLD='address=/localhost/127.0.0.1' | |
DNSMASQCONF=/usr/local/etc/dnsmasq.conf | |
echo "sudo grep -q $TLD $DNSMASQCONF || sudo echo "$TLD" >> $DNSMASQCONF" | |
sudo grep -q "$TLD" "$DNSMASQCONF" || sudo echo "$TLD" >> "$DNSMASQCONF" | |
if [ -d '/etc/resolver' ]; then | |
echo 'Directory /etc/resolver already exists skipping' | |
else | |
echo 'sudo mkdir -p /etc/resolver' | |
sudo mkdir -p /etc/resolver | |
fi | |
NAMESERVER='nameserver 127.0.0.1' | |
RESOLVER=/etc/resolver/localhost | |
echo "grep -q $NAMESERVER $RESOLVER || echo $NAMESERVER >> $RESOLVER" | |
sudo grep -q "$NAMESERVER" "$RESOLVER" || echo "$NAMESERVER" | sudo tee "$RESOLVER" | |
echo "sudo brew services restart dnsmasq" | |
sudo brew services restart dnsmasq | |
CONTAINER='nginx-proxy' | |
RUNNING=$(docker inspect --format="{{ .State.Running }}" $CONTAINER 2> /dev/null) | |
if [ $? -eq 1 ]; then | |
echo "docker run --restart=always -d --name $CONTAINER -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy" | |
docker run --restart=always -d --name $CONTAINER -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy | |
else | |
echo "Error container by name $CONTAINER already exists" | |
echo "Make sure it is same as below else remove and run command below:" | |
echo "echo "docker run -d --name $CONTAINER -p 80:80 -v /var/run/docker.sock:/tmp/docker.sock:ro jwilder/nginx-proxy"" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment