-
-
Notifications
You must be signed in to change notification settings - Fork 144
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
Comments
I use a Dockerfile that reads:
I use the
requirement.txt is as follows:
|
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. |
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 |
For a Dockercontainer working on a RaspberryPi (model 4 tested) you should use |
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. |
+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. |
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
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 |
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 :) |
@gjelsas could you share the docker image you're currently using, please? This could be helpful for everyone.
The text was updated successfully, but these errors were encountered: