![](/img/trans.png)
[英]Started Flask app using gunicorn + gevent, Listening at: http://127.0.0.1:8000, but no response
[英]Flask App with Gunicorn Dockerized, Listening at: http://0.0.0.0:8000, but URL not responding
在 Ubuntu Linux 服務器上,我有一個作為 Docker 映像運行的 Flask 應用程序(有 4 個路由)。
我的 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時,卻無法連接。
Docker 必須通過-p
/ --publish
命令公開端口! 文檔
sudo docker run -it -p=8000:8000 flaskApp:1.16
正如文檔所說,您需要公開要從主機訪問的端口。 在您的情況下,正確的命令是:
sudo docker run -it -p 8000:8000 flaskApp:1.16
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.