日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

Build Docker image of a Python Flask app【转载】

發布時間:2025/4/5 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 python?docker?flask shareimprove this question asked?Jan 19 '17 at 19:46 srm 10711 silver badge88 bronze badges add a comment

2 Answers

activeoldestvotes 4

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【转载】的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。