【问题标题】:Flask App with Gunicorn Dockerized, Listening at: http://0.0.0.0:8000, but URL not responding带有 Gunicorn Dockerized 的 Flask 应用程序,监听地址:http://0.0.0.0:8000,但 URL 没有响应
【发布时间】:2021-01-17 07:09:58
【问题描述】:

在 Ubuntu Linux 服务器上,我有一个 Flask 应用程序(有 4 个路由)作为 Docker 映像运行。

我的 Dockerfile -

FROM ubuntu:18.04
FROM python:3
RUN apt-get update -y && apt-get install -y python-pip python-dev
COPY . /backend
WORKDIR /backend
RUN pip3 install -r requirements.txt
EXPOSE 8000
CMD gunicorn --bind 0.0.0.0:8000 --workers=4 wsgi:app

当我运行它时 -

sudo docker run -it flaskApp:1.16

标准输出显示

[2020-10-01 14:03:25 +0000] [6] [INFO] Starting gunicorn 20.0.4
[2020-10-01 14:03:25 +0000] [6] [INFO] Listening at: http://0.0.0.0:8000 (6)
[2020-10-01 14:03:25 +0000] [6] [INFO] Using worker: sync
[2020-10-01 14:03:25 +0000] [8] [INFO] Booting worker with pid: 8
[2020-10-01 14:03:25 +0000] [9] [INFO] Booting worker with pid: 9
[2020-10-01 14:03:25 +0000] [10] [INFO] Booting worker with pid: 10
[2020-10-01 14:03:25 +0000] [11] [INFO] Booting worker with pid: 11

但是当我使用服务器的公网IP访问App和API时,却​​无法连接。

  1. 我需要配置其他东西吗?
  2. 我的 Dockerfile 是否正确?

【问题讨论】:

标签: python docker flask gunicorn ubuntu-server


【解决方案1】:

作为documentation says,您需要公开要从主机访问的端口。在您的情况下,正确的命令是:

sudo docker run -it -p 8000:8000 flaskApp:1.16

【讨论】:

    【解决方案2】:

    Docker 必须通过-p/--publish 命令公开端口! docs

    sudo docker run -it -p=8000:8000 flaskApp:1.16
    

    【讨论】:

      猜你喜欢
      • 2011-05-19
      • 1970-01-01
      • 2021-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多