Skip to content

Instantly share code, notes, and snippets.

@pascalandy
Created March 19, 2016 20:09
Show Gist options
  • Select an option

  • Save pascalandy/f79da5796700ba4f607d to your computer and use it in GitHub Desktop.

Select an option

Save pascalandy/f79da5796700ba4f607d to your computer and use it in GitHub Desktop.
nginx-proxy multiple user-defined networks test (PR 337)
#! /bin/bash
# Test for: https://github.com/jwilder/nginx-proxy/pull/337#issuecomment-198494662
echo "Creating networks"
docker network create nptest_other >/dev/null
docker network create nptest_net1 >/dev/null
docker network create nptest_net2 >/dev/null
echo "Starting nginx-proxy"
docker run -d \
--name np_test \
-p 80:80 \
--net=nptest_other \
-v /var/run/docker.sock:/tmp/docker.sock:ro nginx-proxy:overlay >/dev/null
docker network connect nptest_net1 np_test
docker network connect nptest_net2 np_test
echo "Starting web-containers"
for n in net1 net2; do
for w in web1 web2; do
docker run -d --name nptest_${n}_$w --net=nptest_$n -e VIRTUAL_HOST=$w.$n.localhost nginx >/dev/null
docker exec nptest_${n}_$w sed -i "s/Thank you for using nginx./This is $w.$n.localhost./" /usr/share/nginx/html/index.html
done
done
echo "Wait 2 seconds for configuration to finish"
sleep 2
echo "Output from containers:"
for n in net1 net2; do
for w in web1 web2; do
echo " $w.$n.localhost: $(curl -s --header "Host: $w.$n.localhost" http://127.0.0.1 | grep "This is")"
docker rm -f nptest_${n}_$w >/dev/null
done
done
echo "Cleaning up"
docker rm -f np_test >/dev/null
docker network rm nptest_other
docker network rm nptest_net1
docker network rm nptest_net2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment