dockerfile中设置python虚拟环境+gunicorn启动

独自空忆成欢 提交于 2020-08-11 07:27:22
FROM python:2.7-slim
EXPOSE 8000 COPY ./yourapp /home/yourapp RUN apt-get update \ && apt-get install --no-install-recommends --no-install-suggests -y \ default-libmysqlclient-dev \ gcc \ && pip install virtualenv \ && virtualenv /home/yourapp/venv \ && /home/yourapp/venv/bin/pip install --no-cache-dir -r /home/yourapp/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple CMD ["/home/yourapp/venv/bin/gunicorn", "--chdir", "/home/yourapp", "manage:app", "-c", "/home/yourapp/gunicorn.conf"] 

 

我们不需要在RUN中进行source venv/bin/acitvate,只要pip的路径是虚拟环境下的就可以。然后gunicorn的命令需要有--chdir把路径定位至manage所在位置。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!