Created
February 17, 2017 12:41
-
-
Save bakketun/9c8444e032934f7ad7c723b817340e0e to your computer and use it in GitHub Desktop.
Test if docker keeps manually assigned IPs
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 | |
num_containers=5 | |
docker network create -d bridge --subnet 172.99.0.0/16 test | |
for i in $(seq $num_containers) ; do | |
containers="$containers $(docker run --network test --ip 172.99.1.$i --restart on-failure:10 -d nginx)" | |
done | |
show_ips() { | |
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $containers | |
} | |
echo "IPs before crash" | |
show_ips | |
sudo killall -9 nginx | |
sleep 3 | |
echo "IPs after crash" | |
show_ips | |
echo | |
echo "IPs before restart" | |
show_ips | |
docker stop $containers | |
docker start $containers | |
echo "IPs after restart" | |
show_ips | |
docker rm -f $containers | |
docker network rm test |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment