Kristian Glass - Do I Smell Burning?

Mostly technical things

Packaging Django With Docker

I love Docker as a packaging system - almost everything I push to production nowadays is as a Docker image.

Occasionally in the #django IRC channel, the topic of “how to Docker-ise your Django service” comes up. Here’s the Dockerfile I use, taken from My Django Project Template:

FROM python:3.5

COPY requirements.txt /opt/{{ cookiecutter.org_name }}/{{ cookiecutter.app_name }}/
WORKDIR /opt/{{ cookiecutter.org_name }}/{{ cookiecutter.app_name }}/

RUN pip install --no-deps --requirement requirements.txt

COPY . /opt/{{ cookiecutter.org_name }}/{{ cookiecutter.app_name }}/

RUN python {{ cookiecutter.app_name }}/ collectstatic --noinput


CMD gunicorn --chdir {{ cookiecutter.app_name }} --bind {{ cookiecutter.app_name }}.wsgi


  1. It’s fairly minimal; it installs dependencies, calls collectstatic, and runs. Nothing else. Everything else is the job of the platform I deploy to
  2. It uses gunicorn as a WSGI HTTP server, because it does exactly what I need and not much more - HTTP in one end, WSGI in the other. uwsgi has so many command-line options I don’t actually know how to run it, and looks like it’s designed more as an all-in-one server platform with Emperor mode and its own stats server etc. etc. which is much more heavyweight than I want
  3. It does very little about media and staticfiles, leaving them to be handled by (usually) AWS S3 and Whitenoise, respectively

Hope this helps!