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.

Now that you’ve accessed the container registry and have your configuration files, it’s time to create a disk image and set up a virtual machine.

Prerequisites:

  • A no-cost Red Hat Developer subscription.
  • Podman Desktop.
    • You can download Podman Desktop for Windows, macOS, or Linux.
  • The configuration files in the django-dev/bootc directory from the previous lesson:
    • django.service
    • nginx-myproject.conf  
    • containerfile
  • Your development files from Lesson 2, which are in the django-dev/bootc/app directory.

In this lesson, you will:

  • Create your first disk image.
  • Build an image from the containerfile.
  • Build a disk image.
  • Set up a virtual machine (VM).

Create your first disk image

In Lesson 1, we installed the Red Hat Extension Pack, which includes the Bootable Containers extension used for image mode deployments. To pull your first bootable container, follow these steps:

  1. In Podman Desktop, select Bootable Containers from the side menu bar to access the Dashboard section (Figure 1). 

    A view of the Welcome to Bootable Containers dashboard screen in Podman Desktop.
    Figure 1: Welcome to Bootable Containers dashboard screen.
  2. Within the Bootable Containers section, select Images from the left navigation. 
  3. On the Images screen, select the option to pull the example container image from registry.gitlab.com (Figure 2). 

    Bootable Containers > Images showing the container pulled from registry.gitlab.com.
    Figure 2: Bootable containers images listing screen with the example image now available.
  4. Once you complete this, you will see the example image. 

Note

The file size of the image is over 700MB (compressed) and may take a while to download. 

Build an image from the containerfile

Next, let’s use the Containerfile we created in Lesson 3 to build an image:

  1. Open Podman Desktop on your local machine and go to the Images section in the left navigation.
  2. Select Build to open the Build image from the Containerfile screen.
  3. Provide the following:
    1. Containerfile path: your_home_directory/django-dev/bootc/containerfile,
    2. Build directory path: your_home_directory/django-dev/bootc
    3. Image name: django-bootc-image
    4. Platform hardware spec: I chose the Intel and AMD x86_64 image option for my desktop environment (Figure 3).

      Podman Desktop > Images > Build > Build image from Containerfile.
      Figure 3: The Build image from Containerfile screen in Podman Desktop.
  4. Select Build once you have all of the information entered. Observe if any issues or warnings are displayed while building the image. Once you’ve successfully created the image (Figure 4), it will be listed on the Images dashboard (Figure 5).

    Successfully created image shown in the Images dashboard.
    Figure 4: Successful Containerfile build output in Podman Desktop.
    The images screen shows the new image we just created.
    Figure 5: The container images listing screen with a new entry for the example image.

At this point, our image can run like any other container with Podman. This can be highly beneficial for basic testing and iterating on your application. In the next step, you will install (write) your container image as a disk image and run it as a Linux system. 

Build a disk image

While a traditional application container image is like a self-contained software package that you install onto an existing OS, image mode uses bootc to deliver a complete, bootable OS installation disk, but managed and versioned like a container image. The magic of bootc is that it can install the contents of the container image to disk or file system and provide any format you need to run on virtually any platform. Podman Desktop makes this process simple, and you can target a wide variety of platforms and image types.  

To build an image in Podman Desktop:

  1. Open Podman Desktop on your local machine and go to the Images section from the left navigation. If you just completed the prior steps, you will already be on this screen.
  2. Select the option to Build Disk Image from the ACTIONS kebab (Figure 6).

    The Podman Desktop container images screen with the expanded menu under the actions kebab.
    Figure 6: The Podman Desktop container images screen with the expanded menu under the actions kebab.
  3. Select Build on the Disk Images.
  4. Provide the configuration details. For the purposes of this exercise, we chose Virtualization Guest Image (qcow2) as the image type and a default filesystem (Figure 7). 

    The completed Build Disk Image configuration.
    Figure 7: The completed Build Disk Image configuration.
  5. Expand the Interactive build config section towards the bottom of the screen. This is where you will enter your SSH credentials you will need for the next section (Figure 8). 

    The Build Disk Images and Interactive build config screen to enter the  SSH credentials.
    Figure 8: The expanded interactive build config section for building a disk image in Podman Desktop.
  6. Select Build.
  7. Observe if any issues or warnings are displayed while building the disk image. Once you’ve successfully created the image, you will see a success message (Figure 9)  listed in the Bootable Containers > Disk Images section of Podman Desktop.

    This is a pop-up message indicating that the disk image successfully installed.
    Figure 9: A successful disk image build.

Set up a virtual machine

Virtual environments provide a quick and convenient way to test your images. You can test modifications and configurations without impacting your primary operating system or incurring cloud expenditures. Once your image has been validated and you’re happy with it, we encourage you to create images for all the platforms you’d like to target.  

Podman Desktop version 1.8.0 and later makes it easy to launch your built disk image as a virtual machine. After successfully building your disk image, simply select Virtual Machine (Experimental). Before doing so, please ensure you've met the necessary prerequisites, which may include specific hardware or software requirements. 

Summary

This learning path demonstrates how easy it is to add the Red Hat SSO extension to Podman Desktop and access the Red Hat registry to create a Django-based application container image that is ready to boot and run with image mode. You can easily extend the rudimentary bootable Django application container you created into a functional application. 

As a developer, there are several reasons why you should care about deploying the application in image mode:

  • Full-stack reproducibility: Image mode allows you to define your app, user space, and the entire OS, ensuring consistency from development to production.
  • Simplified OS management: You can now treat OS updates and configurations as image rebuilds, integrating them into your existing container workflows.
  • Ideal for appliances and edge: Image mode is perfect for creating specialized software appliances or consistent OS environments for edge devices with tightly coupled OS and applications.
  • Testing: With image mode, it is easy to spin up VMs on your desktop or in the cloud, running the exact OS and application build for testing.

The next steps you could take in completing your application might include the following:

  • Extending the application code beyond the prototype "Hello World."
  • Integrating the application with a database, such as SQLLite, MariaDB, MySQL, and PostgreSQL.
  • Configuring keys and infrastructure to improve the security of the NGINX server component.

Want to learn more? Check out:

Previous resource
Build and run a bootable Django application disk image in Podman Desktop using image mode.