azure - 在 Azure 上工作但不在本地工作的 Docker 中的烧瓶
问题描述
这是我的代码(app.py):
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Hello World composcan"
if __name__ == "__main__":
app.run(debug=True,host='0.0.0.0', port=8002)
当我使用这个 dockerfile 时:
FROM ubuntu:18.04
MAINTAINER bussiere "bussiere@composcan.fr"
RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
RUN echo "nameserver 80.67.169.12" >> /etc/resolv.conf
RUN echo "nameserver 208.67.222.222" >> /etc/resolv.conf
#RUN echo "dns-nameservers 8.8.8.8 8.8.4.4 80.67.169.12 208.67.222.222" >> /etc/network/interfaces
ENV LANG C.UTF-8
RUN apt-get update -y
RUN apt-get install -y --no-install-recommends apt-utils
RUN apt-get install -y python3 python3-pip python3-dev build-essential
RUN python3 -m pip install pip --upgrade
RUN python3 -m pip install pipenv
RUN export LC_ALL=C.UTF-8
RUN export LANG=C.UTF-8
COPY app /app
WORKDIR /app
RUN pipenv --python 3.6
RUN pipenv install -r requirements.txt
ENTRYPOINT ["pipenv"]
CMD ["run","python","app.py"]
它完美地适用于天蓝色:
http://koalabourre.azurewebsites.net/
但是当我尝试从 ubuntu 上的 docker 本地运行它时:
docker run --rm -it -p 8002:8002 flask-quickstart
我有 :
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://127.0.0.1:8002/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 101-413-323
我无法使用 localhost:8002 在浏览器中打开它
这是项目的组织:
码头工人在这里 https://hub.docker.com/r/dockercompo/koalabourre/
并且在本地容器外运行 app.py 可以完美运行...
解决方案
您必须监听“外部”(docker 网络)地址才能转发端口。在我看来,您的代码在这方面与程序的输出不太匹配。
你的代码说
app.run(debug=True,host='0.0.0.0', port=8002)
但是你的输出说
* Running on http://127.0.0.1:8002/ (Press CTRL+C to quit)
推荐阅读
- android-jetpack-compose - 如何使用jetpack compose为ConstraintLayout提及dimensionRation?
- python - 蒙特卡洛高斯函数
- javascript - 在每个级别生成聚合直到父级
- python - pyqt 没有显示我的进度条,但它需要时间来完成它
- reactjs - React 路由器 NavLink 活动视图匹配
- javascript - 如何替换反斜杠?
- python - (Python)有人可以帮我解决我的代码有什么问题吗?
- freertos - FreeRTOS 的调度程序的复杂性是多少?
- c++ - 在其自己的模板化成员方法中获取类的类型
- node.js - 节点未更新最新版本