Build a bootable Python Django app with image mode and Podman

Use Podman Desktop to create a bootable Django-based application using image mode for RHEL, integrating Django, Gunicorn, and NGINX.

Overview: Build a bootable Python Django app with image mode and Podman

If you’re looking to rapidly develop and deploy web-based applications in Python, an excellent choice is the combination of Django, Gunicorn, and NGNIX. The quickest way to deploy this powerful stack is as a bootable container either on-premise or in the public cloud, but configuring these components to work together in an SELinux environment can be tricky. This learning path is designed to get you up and running quickly.

Red Hat Enterprise Linux (RHEL) now supports image mode, a new deployment method that allows you to take a container-native approach to deploying a fully bootable operating system environment on bare metal or virtual machines targeting on-premise or cloud deployment.

Image mode allows you to define an entire system from the RHEL base to your Django application and its dependencies, using a Containerfile. Instead of configuring a base OS and then deploying your app container onto it (and hoping the OS stays consistent), your Django app and the underlying RHEL operating system are intrinsically linked and built from a single definition. You can leverage your existing knowledge of Containerfile syntax and container build processes to create a full disk image (i.e., qcow2, AMI, ISO, etc.). 

Let's say your Django app needs specific system libraries or configurations at the OS level. You can add these directly into the same Containerfile that sets up your Python environment. This approach offers more consistency across building, testing, and production. 

The bootable image you develop and test locally with Podman Desktop can be the same image deployed as a virtual machine in staging or production. Because the OS and the app are one unit, if it boots and runs for you, it boots and runs the same way everywhere, mitigating many common issues of inconsistent performance. Deploying the application with a bootable container greatly simplifies reproducing the application and its environment as well as troubleshooting and debugging.

While all this sounds great, building image mode containers for applications that require in-container interprocess communication can be tricky, because you have to account for technologies like SELinux, which you manage differently if you’re running in a traditional container application environment versus a bootable one. This comes into play when you’re trying to use Django, Gunicorn, and NGINX together.

Prerequisites:

  • A no-cost Red Hat Developer subscription.
  • Podman Desktop.
    • You can download Podman Desktop for Windows, macOS, or Linux (Fedora or RHEL).

In this learning path, you will:

  • Access the Red Hat Container Registry.
  • Learn how to install the Red Hat Single Sign-On (SSO) extension.
  • Build a sample Python Django application in a container used for development.
  • Build and run a bootable Django application disk image in Podman Desktop using image mode.