【发布时间】:2022-01-26 02:24:27
【问题描述】:
我正在尝试使用 Elastic Beanstalk 上的 Docker 启动并运行一个超级简单的 Flask 服务器。当我导航到与 EB 环境关联的域时,我看到的只是一个巨大的 502 Bad Gateway Error。
再深入一点,我在 EB 的 Nginx 日志中看到以下错误:
2021/12/26 01:00:24 [error] 16944#16944: *682 connect() failed (111: Connection refused) while connecting to upstream, client: 172.31.23.137, server: , request: "GET / HTTP/1.1", upstream: "http://172.17.0.2:5000/", host: "172.31.1.207"
在eb-stdouterr.log 中,它报告服务器已启动并正在运行:
web_1 | * Serving Flask app 'app' (lazy loading)
web_1 | * Environment: production
web_1 | WARNING: This is a development server. Do not use it in a production deployment.
web_1 | Use a production WSGI server instead.
web_1 | * Debug mode: on
web_1 | * Running on all addresses.
web_1 | WARNING: This is a development server. Do not use it in a production deployment.
web_1 | * Running on http://172.24.0.2:5000/ (Press CTRL+C to quit)
我找到了与 EC2 实例关联的公共 IP 地址,并且我实际上能够使用 curl 查询到预期结果,所以感觉这是一个 DNS 问题。有什么提示或建议吗?我真的不知道如何进一步调试。
配置:
- AWS Linux 2
- Docker Python 映像 3.9-buster
- Flask 服务器
编辑:从 AWS documentation 看来,使用 docker-compose 意味着您不应该使用 Nginx? 我去禁用了它,但我仍然遇到 502 Bad Gateway 问题和没有相关的错误日志。
这是我的Dockerfile:
# syntax=docker/dockerfile:1
FROM python:3.9-buster
COPY . /code
WORKDIR /code
COPY requirements.txt requirements.txt
RUN apt-get update -y && \
apt-get install -y python-pip python-dev && \
pip install --upgrade pip && \
pip install -r requirements.txt
EXPOSE 5000
COPY . .
CMD python app.py
这是我的docker-compose.yml:
version: "3.9"
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
请帮忙,提前谢谢:D
【问题讨论】:
-
在一些 AWS 文档中发现了这个有趣的注释“Elastic Beanstalk 假定您将 Web 服务器代理作为容器运行。” docs.aws.amazon.com/elasticbeanstalk/latest/dg/…
标签: nginx dns amazon-elastic-beanstalk