3 min read

Running a simple Django website in Docker

Using Docker to run a simple production and development environments with a few extras thrown in. Easily customized to your preferred language or framework.

Running a simple Django website in Docker
Isaac Bythewood Isaac Bythewood
2022-05-14

Docker is a near perfect solution for having project portability across a wide variety of host platforms. I use docker to run my websites on both development computers and servers. For Django my go to Dockerfile looks a little something like this.

A few notes on my choices:

  • This assumes you are just using an sqlite database but this can easily scale into using PostgreSQL in coordination with docker-compose
  • I use webpack to build all of my static files on all of my sites hence why nodejs and yarn are included
  • Chromium is used in most of my projects for generating PDFs and screenshots, I've found it the most reliable and consistent way of handling that functionality
  • You'll need both gunicorn and uvicorn installed

You could remove Chromium and save ~400MB of space on a roughly ~450MB image if you have no use for it. It is by far the largest dependency here. I also often use docker-compose in conjunction with this Dockerfile.

This can be used directly in production pretty well however I do put most of my websites behind Caddy using a reverse proxy. If you'd like to see my most up-to-date alpine-docker files you can check them out on my overshard/dockerfiles GitHub project.


Some posts in similar tags to this one.

Finding broken external links on websites using Scrapy
Finding broken external links on websites using Scrapy
Broken links are a problem for any content driven website as it ages, find them quickly and easily with Scrapy.
Isaac Bythewood Isaac Bythewood
2022-07-23
Adding dark mode with automatic system preference selection
Adding dark mode with automatic system preference selection
Creating a dark, or light, version of your website may seem like a daunting task if you think you need an entirely new color pallet. It's 2022 though and we have the widely supported invert CSS filter.
Isaac Bythewood Isaac Bythewood
2022-07-02
Creating a PWA with Next.js and next-pwa to improve your websites UX
Creating a PWA with Next.js and next-pwa to improve your websites UX
Turning your website into a PWA, especially if your website doesn't rely on an internet connection at all, can greatly improve its user experience by allowing them to access your web app anywhere.
Isaac Bythewood Isaac Bythewood
2022-06-18