Skip to content

Instantly share code, notes, and snippets.

@jobwat
Created March 10, 2017 01:09
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 jobwat/5ce3cacb2d21ca85491ba845137dd6b6 to your computer and use it in GitHub Desktop.
Save jobwat/5ce3cacb2d21ca85491ba845137dd6b6 to your computer and use it in GitHub Desktop.
Docker nodes load balancer with nginx upstream
# Run 3 nodes
for i in 1 2 3; do
nod="n$i"
mkdir $nod
echo "$nod" >> $nod/index.html
docker run -d --name $nod -p 888${i}:80 -v `pwd`/${nod}:/usr/share/nginx/html:ro nginx
done
# Run a router proxy node
docker run --rm --name router -p 8888:80 -v `pwd`/default.conf:/etc/nginx/conf.d/default.conf nginx
# reload nginx from outside
docker exec -ti router nginx -s reload
upstream app {
server 192.168.99.100:8881;
#server 192.168.99.100:8882;
server 192.168.99.100:8883;
}
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://app;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment