简体   繁体   English

在docker容器内的virtualenv上运行flask应用

[英]Running flask app on virtualenv inside docker container

So I am trying to run a flask app inside of a virtualenv on a docker container. 所以我试图在docker容器上的virtualenv内部运行flask应用程序。

My Dockerfile looks like this 我的Dockerfile看起来像这样

FROM ubuntu:latest
MAINTAINER Gabriel Togni "togni@nmmi.edu"
RUN apt-get update -y
RUN apt-get install -y python-pip python-dev build-essential python-virtualenv
COPY . /app
WORKDIR /app

RUN virtualenv test

WORKDIR test

RUN /bin/bash -c "source test/bin/activate; pip install -r requirements.txt"

ENTRYPOINT /bin/bash -c "source test/bin/activate; python app.py"

It builds with no errors, it runs with no errors, but it is not working. 它生成没有错误,它运行没有错误,但是没有用。

My requirements.txt file only has Flask==0.12.2 and my app.py looks like this 我的requirements.txt文件只有Flask==0.12.2而我的app.py看起来像这样

from flask import Flask
import sys
app = Flask(__name__)

@app.route("/")
def hello():
        if getattr(sys, "real_prefix", None) is not None:
                return "Maybe in a virtualenv"
        else:
                return "Probably not in a virtualenv"

if __name__ == "__main__":
    app.run(debug=True, host='0.0.0.0')

I am trying to do this on an Ubuntu Server 16.04.3 LTS 我正在尝试在Ubuntu Server 16.04.3 LTS上执行此操作

EDIT-- 编辑 -

The problem was fixed after I added the ; 我添加了;之后,问题已解决; to my code on 对我的代码

RUN /bin/bash -c "source test/bin/activate; pip install -r requirements.txt"

ENTRYPOINT /bin/bash -c "source test/bin/activate; python app.py"

The entrypoint will be run in WORKDIR . 入口点将在WORKDIR运行。 Your file app.py is not on /app , which is your WORKDIR , it is on /app/test . 您的文件app.py不在/app ,它是您的WORKDIR ,在/app/test You must send the path for the entrypoint command, as he doesn't find the file in current directory: 您必须发送entrypoint命令的路径,因为他在当前目录中找不到该文件:

ENTRYPOINT /bin/bash -c "source bin/activate python test/app.py"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM