Build Docker image of a Python Flask app【转载】
原文地址:https://stackoverflow.com/questions/41750366/build-docker-image-of-a-python-flask-app
I'm trying to build a Docker image for a Python Flask app but having build problems - all files live in a folder called web
- this is the project structure:
web/__init__.pyapp.pyDockerfilemodels.pyrequirements.txt
and app.py
at the moment looks like this:
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')
I've borrrowed the Dockerfile
from https://www.smartfile.com/blog/dockerizing-a-python-flask-application/:
FROM ubuntu:14.04# Update OS
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade# Install Python
RUN apt-get install -y python-dev python-pip# Add requirements.txt
ADD requirements.txt /webapp# Install wsgi Python web server
RUN pip install uwsgi
# Install app requirements
RUN pip install -r requirements.txt# Create app directory
ADD . /webapp# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp# Expose port 8000 for uwsgi
EXPOSE 8000ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
I'm trying to build the Docker image using docker build --no-cache --rm -t flask-app
, but it ends with an error message:
Successfully installed uwsgi
Cleaning up...---> 9bbc004212a3
Removing intermediate container 70ed8f07c408
Step 8/13 : RUN pip install -r requirements.txt---> Running in f5e2eb59ffd1
Could not open requirements file: [Errno 2] No such file or directory: 'requirements.txt'
Storing debug log for failure in /root/.pip/pip.log
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 1
2 Answers
I think a very small change on your Dockerfile would fix this:
FROM ubuntu:14.04# Update OS
RUN sed -i 's/# \(.*multiverse$\)/\1/g' /etc/apt/sources.list
RUN apt-get update
RUN apt-get -y upgrade# Install Python
RUN apt-get install -y python-dev python-pip# Add requirements.txt
# Create app directory
ADD . /webapp# Install wsgi Python web server
RUN pip install uwsgi
# Install app requirements
# Full path to requirements
RUN pip install -r /webapp/requirements.txt# Set the default directory for our environment
ENV HOME /webapp
WORKDIR /webapp# Expose port 8000 for uwsgi
EXPOSE 8000ENTRYPOINT ["uwsgi", "--http", "0.0.0.0:8000", "--module", "app:app", "--processes", "1", "--threads", "8"]
I just added the full path to requirements.txt
, this could be accomplished in several different ways, like copying the entire directory folder and then building it.
转载于:https://www.cnblogs.com/davidwang456/articles/11315438.html
Build Docker image of a Python Flask app【转载】相关推荐
- 「docker实战篇」python的docker-打造多任务端app应用数据抓取系统(下)(35)
上次已经把python文件挂载到虚拟机上了,这次主要设置下虚拟机通过docker容器的方式. 运行 python 代码运行 >启动一个crt的会话 docker run -it -v /root ...
- Python flask 特殊装饰器 @app.before_request 和 @app.after_request 以及@app.errorhandler介绍
特殊装饰器 @app.before_request 和 @app.after_request以及@app.errorhandler() 一.背景: Flask我们已经学习很多基础知识了,现在有一个问题 ...
- 为 Python Web App 编写 Dockerfiles
原文地址:How to write Dockerfiles for Python Web Apps 原文作者:Praveen Durairaj 译文出自:掘金翻译计划 本文永久链接:github.co ...
- Docker容器化部署python
1. 简介 Docker是目前主流IT公司广泛接受和使用的,用于构建.管理和保护它们应用程序的工具. 容器,例如Docker允许开发人员在单个操作系统上隔离和运行多个应用程序,而不是为服务器上的每个应 ...
- dockerfile构建一个(python+flask+html)镜像 + 上传到阿里云私有仓库 + 部署到k8s---全过程
前言 因为之前根据一些网上的教程一个个部分实践过整个部署流程,但都是根据现有的程序/ymal文件等进行创建部署,未能根据自己特定的项目进行部署.因此,这篇博文,打算完整部署一个自己编写的python+ ...
- python flask项目过程_Python 开发过程遇到的问题
另一方面,也是因为时间原因,没有事先系统了解 python 的具体内容,所以开发过程中基本都是拿 java 的东西往 python 里面套. 比如: 某个功能用 java 的 ArrayList 可以 ...
- flask mysql 1366_2017-11-17 Python Flask Script+mysql环境设置
[1.初级版] flask-scrpit安装. 使用flask-scrpit可以创建命令,并在Flask的应用上下文中执行,因为这样才能对Flask对象进行修改.Flask Script自带了一些默认 ...
- ci/cd heroku_在GitLab上设置CI / CD以在Heroku上部署Python Flask应用程序
ci/cd heroku Recently I came across a challenge to deploy a Python Flask web application to Heroku. ...
- Python Flask教程
Welcome to Python Flask tutorial. In previous lesson we have learnt about python lambda. Python flas ...
最新文章
- 需求旺盛:市场提供大量机器学习与物联网相关岗位
- 我的CCIE实验考试
- Sql Server 三个很有用的函数
- 读《程序员到底怎么了?-》
- (转)WindowsPhone基础琐碎总结-----数据绑定(一)
- python编辑elif显示错误_Python运行的17个时新手常见错误小结
- python保存图片_python保存网络图片问题
- Python tkinter的text控件加滚动条
- 广西移动计算机面试题,广西移动笔试经验分享
- 继承(1)----《.NET 2.0面向对象编程揭秘 》学习
- kei4的安装教程(附下载地址)
- 几个实用又好看的纯css 按钮样式
- matlab randn 范围,如何用matlab编写randn函数?
- 2020年5月面试精心整理java面试题,覆盖了大部分面试题(附答案)
- 视频画面添加图片,这个方法分享给你
- 群晖Docker 安装Jellyfin提示“操作超时解决方法
- EC-Net: a Edge-aware Point set Consolidation Network
- BitLocker是个什么东东?密钥丢了怎么办
- 光盘、软盘、硬盘、U盘、磁条卡、芯片卡和复合卡之间的区别与联系
- 三菱系统四轴正反转参数_三菱M70四轴调试
热门文章
- C++存储和处理字符串
- linux c 多态原理,看了所谓的面向对象中靠继承多态实现的所谓重用 哥笑了
- 简述计算机的网络技术,简述新式计算机网络技术及应用
- 开机f8修复电脑步骤_知识 | 8种方法修复电脑无法开机问题
- 简短的python金融数据分析师_让一位数据分析师崩溃有多简单?
- 2019帝豪gs装软件_短试新帝豪GS:冷门的跨界SUV,为什么吉利能做成爆款?
- mysql 级联同步不成功_MySQL级联复制的同步问题(一)
- 服务端升级为select模型处理多客户端
- Dictionary泛型集合
- 把mysql部署在局域网的服务器上,远程连接mysql时报错误代码1130 Host ‘***.***.***.***’is not allowed to connect to this MySQL