wonderbeyond
10/16/2017 - 10:06 AM

Dockerfile: Python3+Django+Gunicorn, with customed apt&pypi mirror

Dockerfile: Python3+Django+Gunicorn, with customed apt&pypi mirror

FROM python:3

RUN /bin/echo -e \
"deb http://mirrors.aliyun.com/debian/ jessie main non-free contrib\n"\
"deb http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib\n"\
"deb-src http://mirrors.aliyun.com/debian/ jessie main non-free contrib\n"\
"deb-src http://mirrors.aliyun.com/debian/ jessie-proposed-updates main non-free contrib\n"\
> /etc/apt/sources.list

# build deps
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    python3-dev \
    libjpeg62-turbo libjpeg62-turbo-dev zlib1g zlib1g-dev \
    libpcre3-dev \
    git \
    openssh-client

# for pip install from git repos.
COPY ./myproj.pem /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN /bin/echo -e "Host *\n\tStrictHostKeyChecking no" > /root/.ssh/config

RUN mkdir -p ~/.pip && /bin/echo -e \
"[global]\n"\
"index-url = http://mirrors.aliyun.com/pypi/simple/\n"\
"trusted-host = mirrors.aliyun.com\n"\
> ~/.pip/pip.conf

COPY ./requirements.txt /tmp/requirements.txt
RUN pip install --no-cache-dir -r /tmp/requirements.txt

# Web app source code
COPY ./myproj /code
WORKDIR /code

ENV APP_ENV=prod

CMD [ \
    "gunicorn", \
    "--bind=0.0.0.0:8000", \
    "--worker-class=gthread", \
    "--workers=5", \
    "--threads=6", \
    "--access-logfile=-", \
    "myproj.wsgi" \
]