Docker, from image to production
Build a production image, run it with Compose, ship it from CI, and check the result.
This path takes Django from a Dockerfile to containers in production: a solid image with a proper entrypoint and a non-root user, Compose with dev and prod overrides, environment handling, a smaller image that builds fast, a registry, and a proxy with automatic HTTPS.
Each step builds on the image from the step before, and the path finishes with the Docker production checklist.
The steps
- How to Dockerize a Django App for Production
A Dockerized Django app that works in development is not automatically safe for production.
- Write a Docker Entrypoint Script for Django
Write a robust docker-entrypoint.sh for Django: wait for dependencies, optionally run migrations and collectstatic behind flags, support web, worker, and one-off commands, exec the final process for signals, and keep secrets out of logs.
- Run a Django Docker Container as a Non-Root User
Run Django containers as a non-root user: create a dedicated user in the Dockerfile, fix ownership of app, static, and media paths, handle volume permissions, bind high ports, and add a read-only root filesystem and dropped capabilities.
- Deploy Django with Docker Compose in Production
Many Docker Compose examples for Django are built for local development, not production.
- Separate Dev and Prod With Docker Compose Override Files
Use one compose.yaml for a Django stack with compose.override.yaml for development and compose.prod.yaml for production: bind mounts and runserver locally, built images, restart policies, and no exposed database ports in production.
- Fix Environment Variables Not Loaded in Docker Compose
Fix Django settings missing environment variables under Docker Compose: .env versus env_file, variable precedence, recreating containers, $ in values, build-time versus runtime, and docker compose config.
- Build Smaller, Faster Django Docker Images
Shrink and speed up Django Docker images: slim base images, multi-stage builds, layer ordering, BuildKit cache mounts, .dockerignore, and measurement.
- Speed Up Django Docker Builds With Layer and Cache Mounts
Make Django Docker builds fast in CI and locally: order layers so dependencies cache, BuildKit cache mounts for pip and uv, registry-backed cache for CI, .dockerignore, and multi-stage builds that compile once.
- Deploy Django Docker Images from GitHub Container Registry
Build Django images in GitHub Actions, push them to GHCR with immutable tags, pull them on servers with read-only credentials, deploy by tag or digest, and clean up old versions.
- Build Multi-Architecture Django Docker Images
Build Django images for both amd64 and arm64 (Graviton, Ampere, Apple Silicon) with docker buildx: QEMU versus native runners, wheels, caching in GitHub Actions, and verifying manifests.
- Deploy Django with Traefik and Docker
Put Traefik in front of a Dockerized Django app: automatic Let's Encrypt certificates, HTTP to HTTPS redirects, Docker labels for routing, static files, and upload limits.
- Django Docker Production Checklist
Review a Dockerized Django deployment before production: image build, non-root user, secrets, health checks, volumes, logging, resource limits, and release steps.