在Azure上但不在本地工作的Docker中的烧瓶

时间:2018-08-11 00:07:49

标签: azure docker flask

这是我的代码(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在浏览器中打开它

这是项目的组织:

enter image description here

码头工人在这里 https://hub.docker.com/r/dockercompo/koalabourre/

并且在容器外部本地运行app.py效果很好...

1 个答案:

答案 0 :(得分:0)

您必须在“外部”(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)