免责声明:我对Docker和gunicorn非常满意。 我正在docker容器中运行Flask应用程序。我正在运行以下内容:
docker run --runtime=nvidia -it my-image:0.1
并在日志中:
[2019-09-18 18:02:21 +0000] [9] [INFO] Booting worker with pid: 9
usage: gunicorn [-h] [--model MODEL] [--cam_id CAM_ID] [--cam_width
CAM_WIDTH]
[--cam_height CAM_HEIGHT] [--scale_factor SCALE_FACTOR]
[--notxt]
gunicorn: error: unrecognized arguments: -b :8080 main:app
我知道这个问题已被问过多次(例如here,here和here),但似乎没有一个答案可以解决。
这是我的Dockerfile
的内容:
FROM gcr.io/deeplearning-platform-release/pytorch-gpu.1-1
RUN apt-get update
ADD . /app
WORKDIR /app
RUN pip install --no-cache-dir -r requirements.txt
ENTRYPOINT ["gunicorn", "-b", ":8080", "main:app"]
和main.py
看起来像这样:
from flask import Flask, request
import model
app = Flask(__name__)
@app.route('/getduration', methods=['POST'])
def get_duration():
try:
video_url = request.args.get('video')
except:
video_url = None
try:
duration = model.run(video_url)
result = str(duration)
return result, 200
except Exception as e:
error = f"There was an error: {e}"
return error, 500
if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
我尝试创建一个包含以下内容的wsgi.py文件:
from main import app
if __name__=="__main__":
app.run()
然后更改了我的Dockerfile入口点:
ENTRYPOINT ["gunicorn", "-b", ":8080", "wsgi:app"]
我想念什么?
请注意,如果我只是在容器中运行python main.py
,则烧瓶应用程序可以正常运行。当我将Dockerfile
入口点更改为CMD ["python", "main.py"]
时,服务器开始运行,但是发出请求时没有任何响应。