If you haven't any application logging facilities alongside the containers, you can use old good tcpdump:
1.
2├── ./app1
3│ ├── ./app1/app1.py
4│ ├── ./app1/Dockerfile
5│ └── ./app1/requirements.txt
6├── ./app2
7│ ├── ./app2/app2.py
8│ ├── ./app2/Dockerfile
9│ └── ./app2/requirements.txt
10├── ./docker-compose.yaml
11├── ./nginx
12│ ├── ./nginx/Dockerfile
13│ └── ./nginx/nginx.conf
14└── ./traffic
15 └── ./traffic/tcpdump.pcap
app1/app1.py
1
2from flask import request, Flask
3import json
4
5app1 = Flask(__name__)
6@app1.route('/')
7
8def hello_world(): return 'This is App1 :) '
9
10if __name__ == '__main__': app1.run(debug=True, host='0.0.0.0')
app1/requirements.txt
1Flask==1.1.1
app1/Dockerfile
1FROM python:3
2COPY ./requirements.txt /requirements.txt
3WORKDIR /
4RUN pip install -r requirements.txt
5COPY . /
6ENTRYPOINT [ "python3" ]
7CMD [ "app1.py" ]
app2/app2.py
1app2/app2.py
2from flask import request, Flask
3import json
4
5app2 = Flask(__name__)
6@app2.route('/')
7
8def hello_world(): return 'This is App2 :) '
9
10if __name__ == '__main__': app2.run(debug=True, host='0.0.0.0')
app2/requirements.txt
1Flask==1.1.1
app2/Dockerfile
1FROM python:3
2COPY ./requirements.txt /requirements.txt
3WORKDIR /
4RUN pip install -r requirements.txt
5COPY . /
6ENTRYPOINT [ "python3" ]
7CMD [ "app2.py" ]
nginx/Dockerfile
1FROM nginx
2RUN rm /etc/nginx/conf.d/default.conf
3COPY nginx.conf /etc/nginx/conf.d/default.conf
nginx/nginx.conf
1upstream loadbalancer {
2server 172.17.0.1:5001 weight=5;
3server 172.17.0.1:5002 weight=5;
4}
5server {
6location / {
7proxy_pass http://loadbalancer;
8}}
docker-compose.yaml
1version: "3"
2networks:
3 tools-network:
4 driver: bridge
5services:
6 app1:
7 build: ./app1
8 ports:
9 - "5001:5000"
10 networks:
11 - tools-network
12 app2:
13 build: ./app2
14 ports:
15 - "5002:5000"
16 networks:
17 - tools-network
18 nginx:
19 build: ./nginx
20 ports:
21 - "8080:80"
22 depends_on:
23 - app1
24 - app2
25 networks:
26 - tools-network
27 tcpdump:
28 image: kaazing/tcpdump
29 network_mode: "host"
30 volumes:
31 - ./traffic:/tcpdump
Комментариев нет:
Отправить комментарий