Skip to content

Instantly share code, notes, and snippets.

@philipz
Last active May 26, 2016 14:22
Show Gist options
  • Save philipz/78abe7476540a85d1e860677c465a5a4 to your computer and use it in GitHub Desktop.
Save philipz/78abe7476540a85d1e860677c465a5a4 to your computer and use it in GitHub Desktop.
Docker Network Alias

Reference

docker network create lb
docker run -d --name nginx1  --net lb --net-alias nginx nginx
docker run -d --name nginx2  --net lb --net-alias nginx nginx
docker run -d --name nginx-lb -p 80:80 -v $(pwd):/data --net lb nginx
docker exec -ti nginx-lb bash

1. In the nginx-lb console

ping nginx
ping nginx
cp /data/proxy.conf /etc/nginx/conf.d/
rm /etc/nginx/conf.d/default.conf
nginx -s reload
exit

2. Check Web Server, then run another nginx.

docker run -d --name nginx3  --net lb --net-alias nginx nginx

3. Check Web Server again. The nginx3 isn't include nginx r-proxy. Into the nginx3 console and reload the nginx daemon.

docker exec -ti nginx-lb bash
nginx -s reload
exit

4. Check Web Server have include nginx3.

upstream myapp1 {
server nginx;
}
server {
listen 80;
location / {
proxy_pass http://myapp1;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment