Docker Alpine for Django, DRF, UWSGi, Postgres and many more


I’m running a couple of project using docker as container engine. Most of them are python related project, which uses django, django rest framework, uwsgi, postgres and packages related to cryptography and much more.

Using the plain python:3 takes up a huge space, so i switched to python:3-alpine

with some problems in adding packages since they do not compile or run.


FROM python:3-alpine 
.. 
COPY requirements.txt . 
RUN set -e; \
 apk add --no-cache --virtual .build-deps \
 gcc \
 libc-dev \
 linux-headers \
 python3-dev \
 musl-dev\
 libffi-dev \
 openssl-dev \
 make \
 ; \
 apk add --no-cache postgresql-dev; \
 pip install --no-cache-dir uwsgi; \
 pip install --no-cache-dir -r requirements.txt; \
 apk del .build-deps; 
..

 

But I found a solution after wasting hours here and there..

Note:

  • that the postgresql-dev is not installed  as virtual.
  • If you want to have uwsgi use the internal routing (e.g., to avoid logs on health checks you have to install (not virtual)
    pcre pcre-dev

    and then use

     pip install --no-cache-dir -I uwsgi;

It install packages and then deletes them from the image. In the end the image is still pretty large 186MB but before it used to be around 7 times more .. (python:3 starts at ~690 MB).

 

Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione /  Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione /  Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione /  Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione /  Modifica )

w

Connessione a %s...