详细使用方法参考以下github网址
https://github.com/nginx-proxy/nginx-proxy
以下是我的docker-compose.yml
version: '3'
services:
nginx-proxy:
image: nginxproxy/nginx-proxy
networks:
- webproxy
ports:
- "80:80"
links:
- whoami2
volumes:
- /var/run/docker.sock:/tmp/docker.sock:ro
whoami2:
image: training/webapp
networks:
- webproxy
expose:
- "5000"
environment:
- VIRTUAL_HOST=域名.cn
#working_dir: /usr/src/app
#ports: # 暴露端口信息 - "宿主机端口:容器暴露端口"
#- "8080:5001"
command: python app.py
whoami3:
image: training/webapp
networks:
- webproxy # 需要绑定到一个网络,才可以互相通信
expose:
- "5000"
environment:
- VIRTUAL_HOST=域名.cn # VIRTUAL_HOST 设置一样的服务就可以实现负载均衡
#working_dir: /usr/src/app
#ports: # 暴露端口信息 - "宿主机端口:容器暴露端口"
#- "9001:5002"
command: python app.py
networks: # 必须要指定的网络
webproxy:
external: true