我有一个具有以下结构的dockerized flask应用程序
code_docker
├── docker-compose.yml
├── micr
│ ├── app.py
│ ├── Dockerfile
│ ├── requirements.txt
│ └── templates
│ └── index.html
├── nginx
│ ├── Dockerfile
│ └── nginx.conf
└── README.md
我使用nginx
作为负载均衡器,下面提到docker-compose.yml
和nginx.conf
中的代码
docker-compose.yml
version: '3'
services:
nginx:
container_name: nginx
build: ./nginx
restart: always
deploy:
restart_policy:
condition: on-failure
ports:
- "8540:8540"
depends_on:
- micr
micr:
build: ./micr
restart: always
deploy:
resources:
limits:
cpus: '0.50' # 50% of available processing time (CPU)
memory: 50M # 50M of memory
reservations:
cpus: '0.25'
memory: 20M
restart_policy:
condition: on-failure
expose:
- "8530"
command: gunicorn -w 1 -b :8530 app:app
nginx.conf
user nginx;
worker_processes 4;
events {
worker_connections 1024;
}
http {
keepalive_timeout 15;
server {
listen 8540;
server_name localhost;
location / {
proxy_pass http://localhost:8530;
#proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forward-Host $server_name;
}
}
}
我可以发出以下命令来缩放容器,而不会出现任何问题,如message
所示docker-compose up --scale micr=4
但是当我尝试访问它们时,出现此错误