代码之家  ›  专栏  ›  技术社区  ›  Bussiere

在Azure上工作的docker中烧瓶,但不是本地烧瓶

  •  1
  • Bussiere  · 技术社区  · 6 年前

    这是我的代码(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"]
    

    它可以在azure上完美运行:

    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/

    和运行应用程序。容器外部的py本地工作非常完美。。。

    1 回复  |  直到 6 年前
        1
  •  0
  •   erik258    6 年前

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