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

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

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"]

 

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

posted on 2020-07-07 20:56  blogsheng  阅读(1735)  评论(0编辑  收藏  举报