Created
February 25, 2014 16:21
-
-
Save bketelsen/9212213 to your computer and use it in GitHub Desktop.
bash script to start N docker containers, stop old versions, and update confd
This file contains hidden or 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 | |
if [ -z "$1" ] | |
then | |
echo "usage : gophercon.sh 3 -- start three new instances" | |
exit -1 | |
fi | |
echo "Getting currently running gophercon containers" | |
OLDPORTS=( `docker ps | grep gophercon | awk '{print $1}'` ) | |
echo "starting new containers" | |
for i in `seq 1 $1` ; do | |
echo "inside loop $1" | |
JOB=`docker run -d -p 80 quay.io/bketelsen/gophercon | cut -c1-12` | |
echo $JOB | |
PORT=`docker inspect $JOB | grep HostPort | cut -d '"' -f 4 | head -1` | |
curl http://127.0.0.1:4001/v2/keys/gophercon/upstream/$JOB -XPUT -d value="127.0.0.1:$PORT" | |
done | |
echo "removing old containers" | |
for i in ${OLDPORTS[@]} | |
do | |
etcdctl rm /gophercon/upstream/$i | |
confd -onetime | |
docker kill $i | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://brianketelsen.com/2014/02/25/using-nginx-confd-and-docker-for-zero-downtime-web-updates/