前言:
此时兄弟们对“flask部署到ubuntu”大概比较注意,朋友们都需要了解一些“flask部署到ubuntu”的相关资讯。那么小编在网络上搜集了一些对于“flask部署到ubuntu””的相关知识,希望你们能喜欢,姐妹们一起来了解一下吧!我试图为PythonFlask应用程序构建一个Docker映像,但是有构建问题-所有文件都位于一个名为web-这是项目结构:
web/ __init__.py app.py Dockerfile models.py requirements.txt
和app.py目前的情况如下:
from flask import Flaskapp = Flask(__name__)@app.route("/")def hello_world(): return "Hello World!"if __name__ == "__main__": app.run(debug=True,host='0.0.0.0')
我已经把Dockerfile从… :
FROM ubuntu:14.04# Update OSRUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.listRUN apt-get updateRUN apt-get -y upgrade# Install PythonRUN apt-get install -y python-dev python-pip# Add requirements.txtADD requirements.txt /webapp# Install wsgi Python web serverRUN pip install uwsgi# Install app requirementsRUN pip install -r requirements.txt# Create app directoryADD . /webapp# Set the default directory for our environmentENV HOME /webappWORKDIR /webapp# Expose port 8000 for uwsgiEXPOSE 8000ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
我试着用docker build --no-cache --rm -t flask-app,但它以错误消息结尾:
Successfully installed uwsgiCleaning up... ---> 9bbc004212a3Removing intermediate container 70ed8f07c408Step 8/13 : RUN pip install -r requirements.txt ---> Running in f5e2eb59ffd1Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'Storing debug log for failure in /root/.pip/pip.logThe command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
我认为对您的Dockerfile进行非常小的更改可以解决以下问题:
FROM ubuntu:14.04# Update OSRUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.listRUN apt-get updateRUN apt-get -y upgrade# Install PythonRUN apt-get install -y python-dev python-pip# Add requirements.txt# Create app directoryADD . /webapp# Install wsgi Python web serverRUN pip install uwsgi# Install app requirements# Full path to requirementsRUN pip install -r /webapp/requirements.txt# Set the default directory for our environmentENV HOME /webappWORKDIR /webapp# Expose port 8000 for uwsgiEXPOSE 8000ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
我刚把完整的路径添加到requirements.txt,这可以通过几种不同的方式来完成,比如复制整个目录文件夹,然后构建它。
原文
版权声明:
本站文章均来自互联网搜集,如有侵犯您的权益,请联系我们删除,谢谢。
标签: #flask部署到ubuntu