$ sudo docker run -itd -p 8001:80 --name lb nginx
$ sudo docker run -itd -p 8002:80 --name serv-a nginx
$ sudo docker run -itd -p 8003:80 --name serv-b nginx
config/default.conf
upstream serv {
server serv-a:80;
server serv-b:80;
}
server {
listen 80;
location /
{
proxy_pass http://serv;
}
}
$ docker cp serv-a/index.html serv-a:/usr/share/nginx/html/
$ docker cp serv-b/index.html serv-b:/usr/share/nginx/html/
FROM nginx
COPY config/default.conf /etc/nginx/conf.d/
FROM nginx
COPY index.html /usr/share/nginx/html
$ docker build -t n-s-1:0.1.0 -f Dockerfile .
$ docker build -t n-s-2:0.1.0 -f Dockerfile .
$ docker build -t lb:0.1.0 -f Dockerfile .
$ docker run --name serv-a -d -p 9001:80 n-s-1:0.1.0
$ docker run --name serv-b -d -p 9002:80 n-s-2:0.1.0
$ docker run --name lb -d -p 8001:80 lb:0.1.0
$ docker network create DockerfileNet
$ docker network connect DockerfileNet serv-a
$ docker network connect DockerfileNet serv-b
$ docker network connect DockerfileNet lb
$ docker network inspect DockerfileNet