68๐
For anyone who is interested in what worked for me (+ some background on why I ran into this):
Installing Pillow will require several dependencies. As far as I can tell, you need: gcc python3-dev jpeg-dev zlib-dev
To prevent these dependencies from ending up in the final image (keeping the image-size small) you can install some (not all!) of them in a virtual package.
After Pillow is installed successfully you can delete the dependencies that are only required for Pillowโs installation.
Dependencies that are only needed during the build are called build dependencies
.
So this is the code that worked for me:
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add postgresql \
&& apk add postgresql-dev \
&& pip install psycopg2 \
&& apk add jpeg-dev zlib-dev libjpeg \
&& pip install Pillow \
&& apk del build-deps
(Some of the stuff is not required for Pillow, e. g. postgressql, postgresql-dev). As you can see, I installed my build dependencies in a virtual package called build-deps
. AFTER installing the build dependencies, I am installing Pillow. At the end, I am removing the build dependencies.
I think, this is the solution that @LinPy proposed: I just wanted to explain this in a very verbose way to help others.
22๐
add this to your Dockerfile
:
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk add --no-cache --virtual .build-deps build-base linux-headers \
&& pip install Pillow
source: Github
- [Django]-Can I call a view from within another view?
- [Django]-How to get field type string from db model in django
- [Django]-How do I deploy Django on AWS?
6๐
I just added these lines to my Dockerfile and it worked
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk del .tmp
My Dockerfile (using python:3.8-alpine):
COPY ./requirements.txt /requirements.txt
RUN apk add --update --no-cache --virtual .tmp gcc libc-dev linux-headers
RUN apk add --no-cache jpeg-dev zlib-dev
RUN pip install -r /requirements.txt
RUN apk del .tmp
- [Django]-CSRF validation does not work on Django using HTTPS
- [Django]-Django, template context processors
- [Django]-Get objects from a many to many field
0๐
Add this to your Docker file
RUN apk add postgresql-dev gcc python3-dev musl-dev jpeg-dev zlib-dev
- [Django]-How does one make logging color in Django/Google App Engine?
- [Django]-How to format time in django-rest-framework's serializer?
- [Django]-Django rest framework serializing many to many field
0๐
#Docker file
FROM python:3.7-alpine
WORKDIR /app
set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
install psycopg2 dependencies
RUN apk update
&& apk add postgresql-dev gcc python3-dev musl-dev libc-dev make git libffi-dev openssl-dev libxml2-dev libxslt-dev zlib-dev jpeg-dev
install dependencies
COPY requirements.txt /app/requirements.txt
RUN pip install โupgrade pip
RUN pip install -r requirements.txt
copy project
COPY . .
Requirement file
Pillow==9.0.0
- [Django]-How to 'bulk update' with Django?
- [Django]-Why second user login redirects me to /accounts/profile/ url in Django?
- [Django]-Django 1.4 timezone.now() vs datetime.datetime.now()
0๐
In my case it worked for me
FROM python:3.9.7-alpine
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
RUN mkdir /backend
ADD ./app /backend
WORKDIR /backend
RUN apk update && \
apk add --virtual .tmp gcc python3-dev jpeg-dev zlib-dev musl-dev libjpeg py3-setuptools \
tiff-dev openjpeg-dev freetype-dev lcms2-dev \
libwebp-dev tcl-dev tk-dev harfbuzz-dev fribidi-dev libimagequant-dev \
libxcb-dev libpng-dev alpine-sdk build-base openssl-dev dateutil tzdata py3-tz && \
pip install --upgrade pip && \
pip install -r requirements.txt && \
echo 'requirements Installed' && \
pip install uvicorn gunicorn && \
apk del .tmp
ENV DB_NAME ******
ENV DB_USER ******
ENV DB_PASSWORD ******
ENV DJANGO_SUPERUSER_PASSWORD ******
CMD gunicorn myproject.asgi:application -k uvicorn.workers.UvicornWorker
- [Django]-Django: how do you serve media / stylesheets and link to them within templates
- [Django]-Django Standalone Script
- [Django]-Django :How to integrate Django Rest framework in an existing application?