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所在位置。