编程语言
首页 > 编程语言> > 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"]

 

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

标签:&&,venv,gunicorn,python,虚拟环境,install,home,yourapp
来源: https://www.cnblogs.com/ExMan/p/13038559.html