Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruddra/870d7a51238ddfa4b50375086c12a4f5 to your computer and use it in GitHub Desktop.
Save ruddra/870d7a51238ddfa4b50375086c12a4f5 to your computer and use it in GitHub Desktop.
Docker with Django, Numpy, Scipy, Gensim and Pandas
# pull official python alpine image
FROM python:3.7-alpine
# Set Environment Variable
ENV PYTHONUNBUFFERED 1
ENV C_FORCE_ROOT true
# Making source and static directory
RUN mkdir /src
RUN mkdir /static
# Creating Work Directory
WORKDIR /src
# Adding mandatory packages to docker
RUN apk update && apk add --no-cache \
postgresql \
zlib \
jpeg \
openblas \
libstdc++
# Installing temporary packages required for installing requirements.pip
RUN apk add --no-cache --virtual build-deps \
gcc \
python3-dev \
musl-dev \
postgresql-dev\
zlib-dev \
jpeg-dev \
g++ \
openblas-dev \
cmake \
&& ln -s /usr/include/locale.h /usr/include/xlocale.h
# Update pip
RUN pip install --upgrade pip
# Installing scipy
RUN pip3 install --no-cache-dir --disable-pip-version-check scipy==1.3.1
# Installing numpy, scipy, psycopg2, gensim
RUN pip3 install --no-cache-dir \
pandas==0.25.2 \
numpy==1.17.3 \
psycopg2==2.8.4 \
gensim==3.8.1 # remove it if not necessary
# Installing requirements.pip from project
COPY ./src/requirements.pip /scripts/
RUN pip install --no-cache-dir -r /scripts/requirements.pip
# removing temporary packages from docker and removing cache
RUN apk del build-deps && \
find -type d -name __pycache__ -prune -exec rm -rf {} \; && \
rm -rf ~/.cache/pip
# CMD will run when this dockerfile is running
CMD ["sh", "-c", "python manage.py collectstatic --no-input; python manage.py migrate; gunicorn mydjango.wsgi -b 0.0.0.0:8000 & celery worker --app=myapp.tasks"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment