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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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 }}/manage.py collectstatic --noinput

EXPOSE 8000

CMD gunicorn --chdir {{ cookiecutter.app_name }} --bind 0.0.0.0:8000 {{ cookiecutter.app_name }}.wsgi

Notably:

  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!

Comments