【发布时间】:2019-08-20 12:41:26
【问题描述】:
我有一个 Flask 应用程序部署在谷歌云计算实例内的容器中,使用 gunicorn 监听端口 5000。
bootstrap.sh 文件:
#!/bin/sh
exec gunicorn -b 0.0.0.0:5000 wsgi:app
我创建了适当的防火墙规则来打开该端口,并使用该规则标记了我的实例。
NAME NETWORK DIRECTION PRIORITY ALLOW DENY DISABLED
rule-allow-tcp-5000 default INGRESS 1000 tcp:5000 False
实例内部的命令netstat -a,显示端口监听:
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 6 0 0.0.0.0:5000 0.0.0.0:* LISTEN
但是当我尝试通过 REST 客户端从外部访问我的实例时,它会无限期地等待响应。
即使在内部,来自实例的 SSH,我也没有响应:
nahuel@instance-1 ~ $ wget localhost:5000
--2019-08-20 12:27:05-- http://localhost:5000/
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:5000... connected.
HTTP request sent, awaiting response...
我认为问题与容器有关,这是我的 Dockerfile:
FROM python:3.6-buster
RUN useradd -m tagger
WORKDIR /home/tagger
COPY requirements.txt requirements.txt
RUN pip install --upgrade pip && pip install -r requirements.txt && pip install gunicorn
COPY autokeras autokeras
COPY static static
COPY tagger tagger
COPY templates templates
COPY model model
COPY application.cfg config.ini tagger-xxxxxx.json main.py wsgi.py bootstrap.sh ./
RUN mkdir uploads
RUN chmod +x bootstrap.sh
ENV FLASK_APP main.py
ENV GOOGLE_APPLICATION_CREDENTIALS tagger-xxxxxx.json
RUN chown -R tagger:tagger ./
USER tagger
EXPOSE 5000
ENTRYPOINT ["./bootstrap.sh"]
当我在本地测试我的容器时,使用 -p 选项运行容器,它工作正常,但我不知道如何让计算实例打开我的容器端口。
感谢您的帮助。
我已经减少了与 Google Instance VM 内的容器有关的问题,正如我在容器日志中看到 gunicorn 正在工作,但它不处理我的请求。
【问题讨论】:
-
docs.bitnami.com/google/faq/administration/use-firewall 。这既不是 Docker 问题,也不是 python ...
-
我已经创建了适当的防火墙规则来打开该端口,并使用该规则标记了我的实例,但我仍然无法访问我的容器端口。即使在 VM 实例内部,我也无法访问容器的 5000 端口。如果我在本地构建和部署,它可以工作。
标签: flask containers google-compute-engine gunicorn