【发布时间】: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时,却无法连接。
- 我需要配置其他东西吗?
- 我的 Dockerfile 是否正确?
【问题讨论】:
-
需要将容器端口发布到宿主机,见Container networking。 The
EXPOSEinstruction does not actually publish the port。在this question 中查看更多信息。
标签: python docker flask gunicorn ubuntu-server