1.先创建主nginx
docker run -itd --name nginx_master -p 8080:80 daocloud.io/nginx /bin/bash
2.从创建
docker run -itd --name nginx_slave1 daocloud.io/nginx /bin/bash docker run -itd --name nginx_slave2 daocloud.io/nginx /bin/bash
3.查看网络
docker network ls docker network inspect 对应你实际NETWORK ID
4.在主nginx配置文件里添加
upstream 172.17.0.2 { server 172.17.0.3 weight=10; # 对应nginx_slave1 weight:权重 server 172.17.0.4 weight=10; # 对应nginx_slave2 } localtion/{}里面要增加proxy_pass http://172.17.0.2否则不生效
配置文件修改后要重启服务:
docker exec -it 容器名 bash
service nginx restart