How to: Run Django using Docker and Docker Compose

Django is my go-to framework at the moment. If I have the chance to voice my opinion on what to use to develop pretty much any new project that comes my way, Django (with WagTail) it is.

That means I ended up creating a starter template for all my Django projects, which includes Docker (and as you will see, does not includes Django).

What I created is a very flexible -for my needs- Docker Compose setup. It is suited for development, and is adaptable to be production ready, although that is a task that needs to be done on a per project basis.

Out of the box you get the following docker images:

The Django image

The Django image is based on Alpine, and uses multi-stage builds to make compiling python packages easy. This is useful for packages like Pillow and Psycopg2 that do not have precompiled wheels for Alpine. Those packages will only be compiled if your app depends on them.

The Caddy image

Caddy is by far the easiest web server I have worked with. It is easy to install, easy to configure and easy to run. But by far its best feature is how easy it is to deal with https, thanks to its integration with LetsEncrypt.

I use CloudFlare for any domain if I can, and I develop with real domains using https (no localhost for my projects), Caddy makes this painless.

The flexibility

All this made easy by Cookiecutter, my favourite project template manager which allows for some initial setup automatic configuration.

But I wont give away any more here go test the template.

Apr 26, 2019

Comments