Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ready-to-go docker images #62

Open
Pierre-Sassoulas opened this issue Jan 24, 2020 · 8 comments
Open

Add ready-to-go docker images #62

Pierre-Sassoulas opened this issue Jan 24, 2020 · 8 comments
Assignees
Labels
enhancement This is a feature not a bug hacktoberfest

Comments

@Pierre-Sassoulas
Copy link
Owner

@gjelsas could you share the docker image you're currently using, please? This could be helpful for everyone.

@Pierre-Sassoulas Pierre-Sassoulas added the enhancement This is a feature not a bug label Jan 24, 2020
@Pierre-Sassoulas Pierre-Sassoulas self-assigned this Jan 24, 2020
@gjelsas
Copy link

gjelsas commented Jan 24, 2020

I use a Dockerfile that reads:

FROM ubuntu:18.04
ARG DEBIAN_FRONTEND=noninteractive
EXPOSE 8000
EXPOSE 22
VOLUME /app
RUN mkdir -p /app/survey
ADD requirement.txt / 
ADD insertUmfrage.py /app/survey/insertUmfrage.py #this is a script to create a survey and users
ADD env.py /app/survey/env.py # for the script see above
ADD survey /app/survey/ # your local django-survey copy, cloned from github
ADD settings.py /app/survey/settings.py #custom settings file 
ADD start.sh / 
ADD authorized_keys /root/.ssh/authorized_keys # for ssh access 
WORKDIR /app/survey
RUN apt update
RUN apt install -y texlive-xetex openssh-server python3 python3-pip
RUN pip3 install -r /requirement.txt 
CMD /bin/sh /start.sh

I use the /start.sh script wich reads:

#!/bin/bash
python3 /app/survey/manage.py makemigrations
python3 /app/survey/manage.py migrate
python3 /app/survey/insertUmfrage.py # see [here](https://github.com/Pierre-Sassoulas/django-survey/issues/57#issuecomment-577920508)
service ssh start 
gunicorn wsgi -b 0:8000 --chdir /app/survey

requirement.txt is as follows:

django
django-rosetta
django-sesame
django-bootstrap-form
gunicorn
pyyaml
django-pandas
pySankey
django-matplotlib
seaborn

@gjelsas
Copy link

gjelsas commented Jan 25, 2020

An Alpine Linux based container would be great, but I struggle with the building of scipy and matplotlib which first take forever, and eventually failes. I would be interested in any suggestions regarding building an Alpine Linux environment with all necessary packages to keep the image small.

@Pierre-Sassoulas
Copy link
Owner Author

I won't be able to check this week but the idea I have is that once we have a working python3/pip3 and once xelatex, python3-tk and matplot dependencies are installed we should be able to install with a simple pip3 install django-survey-and-report. I used the survey app like you - by copying the source directory in my own Django application-, so maybe this approach does not work right now (same problem than #21 ?), but this is what I'm going to try next.

@gjelsas
Copy link

gjelsas commented Jan 29, 2020

For a Dockercontainer working on a RaspberryPi (model 4 tested) you should use FROM debian and RUN apt install -y texlive-xetex openssh-server python3 python3-pip git python3-numpy python3-seaborn python3-pandas otherwise the building of django-pandas might fail...

@saschalalala
Copy link

Regarding Alpine and Python I just recently read a very interesting blog post: https://pythonspeed.com/articles/alpine-docker-python/. It seems like more "mainstream" Linux distributions are a better choice for Python based docker containers.

@Pierre-Sassoulas
Copy link
Owner Author

+1, I also read a similar article since answering this issue (well, the same article in fact, :D). And Alpine packages are also different than what you're probably used to, so there's also development time to consider here.

@pwillis-els
Copy link

I am using the following Dockerfile for a DJango project directory called "mysurvey". The image is about 516MB, which is not ideal, but i'll figure out how to slim it down later. You can add more functionality to this Dockerfile, add a .dockerignore, Volumes, multi-stage builds, etc. But to start with, this is working for me.

Dockerfile

FROM python:3-slim

WORKDIR /app/survey

COPY requirements.txt .
RUN pip3 install -r requirements.txt

COPY mysurvey .
RUN python3 /app/survey/manage.py makemigrations
RUN python3 /app/survey/manage.py migrate

WORKDIR /app/survey/mysurvey

EXPOSE 8000
CMD gunicorn wsgi -b 0:8000 --chdir /app/survey

requirements.txt

django
django-survey-and-report
gunicorn
whitenoise

To use Alpine, you can use a complicated RUN line to install build dependencies (compilers/dev libraries/etc), then build numpy, scipy, matplotlib, and pandas from source, and then remove the deps afterwards. It takes like an hour.

Instead, I'm using alpine:edge, which in the 'testing' branch has a pandas package. So the downside is this is bleeding edge, but the upside is it builds immediately.

The resulting image is 336MB. Not great, but 35% smaller. Still, you can't pin to edge, so not really production-worthy yet. Building from source may still be feasible but I'm too impatient to deal with it now.

FROM alpine:edge

WORKDIR /app/survey

COPY requirements.txt .

RUN echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories \
    && apk add -U --no-cache \
        py3-matplotlib \
        py3-numpy \
        py3-scipy \
        py3-pandas@testing \
        py3-pip \
    && pip3 install --prefer-binary --no-cache-dir \
        -r requirements.txt

COPY mysurvey .
RUN python3 /app/survey/manage.py makemigrations
RUN python3 /app/survey/manage.py migrate

WORKDIR /app/survey/mysurvey

EXPOSE 8000
CMD gunicorn wsgi -b 0:8000 --chdir /app/survey

@Pierre-Sassoulas
Copy link
Owner Author

Thank you for the detailed answer @pwillis-els. I'll accept a merge request with a dockerfile, even if the size of the result is not optimal : I'd rather have a working image than nothing :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement This is a feature not a bug hacktoberfest
Projects
None yet
Development

No branches or pull requests

4 participants