Skip to content

Instantly share code, notes, and snippets.

@gdm85
Created September 19, 2014 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gdm85/e02b1c2d0eb7ada5b590 to your computer and use it in GitHub Desktop.
Save gdm85/e02b1c2d0eb7ada5b590 to your computer and use it in GitHub Desktop.
Testcase for DNS caching bug
#!/bin/bash
## @author gdm85
## tests DNS caching in Docker
##
#
if pgrep dnsmasq >/dev/null; then
echo "You are running dnsmasq, this test would not be consistent" 1>&2
exit 1
fi
echo "Stopping running docker..."
service docker stop >/dev/null 2>/dev/null
echo "Adding index.docker.io override"
echo "127.0.0.1 index.docker.io" >> /etc/hosts
service docker start >/dev/null || exit $?
echo "Waiting for docker to be online..."
## wait for service to be responsive
while ! docker ps >/dev/null 2>/dev/null; do
sleep 1
done
echo "Pulling (expected failure)"
docker pull ubuntu
echo "Pull result is: $? (expected 1)"
## remove the override from /etc/hosts
echo "Now removing index.docker.io override"
sed -i '$ d' /etc/hosts
## expected success
docker pull ubuntu
RV=$?
echo "Pull result is: $RV (expected 0)"
exit $RV
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment