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 a template
Dockerfile I use, taken from My Django Project Template:
It’s does relatively little;
it installs dependencies, calls
collectstatic, and runs.
Most other things are the job of the platform I deploy to.
gunicorn as a WSGI HTTP server,
because it does exactly what I need and not much more.
See my Django: An Unofficial Opinionated FAQ for more here.
It does very little about media and staticfiles, leaving them to be handled by (usually) AWS S3 and Whitenoise, respectively.
It runs as root, because this is normally a minimal concern in the environments I deploy to, and doing otherwise can get fiddly.
It does some minimal
COPY splitting to avoid installing dependencies too needlessly with repeated builds and edits.
In short, it’s far from perfect and rarely what I end up with, but I find it a great place to start from.