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.txtand?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 comment2 Answers
activeoldestvotes 4I 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【转载】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Hadoop YARN:调度性能优化实践
- 下一篇: Docker run 命令【转】