【发布时间】:2019-01-18 14:10:11
【问题描述】:
这是我的代码(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 打开它
这是项目的组织结构:
码头工人在这里 https://hub.docker.com/r/dockercompo/koalabourre/
并且在本地容器外运行 app.py 可以完美运行...
【问题讨论】:
-
我真的很好奇:在容器环境中使用
pipenv有什么好处吗? -
主要修复python版本。但我正在尝试一些事情,所以不要把我的话当成坚如磐石。我也可以在不构建容器的情况下测试我的代码,并确保 python 和模块的版本即使在系统升级后也是相同的。