Skip to content

Building a container image for your software

A container image is a lightweight, standalone software package that includes the code, tools, libraries, and settings required to run a piece of software. The configuration for a container image is stored in a file called a Containerfile.

Prerequisites

  • Podman
  • An RPM package (auto-apps) in an RPM package repository (/var/tmp/my_repo)

Procedure

  1. Create a Containerfile that includes the RPM package that you created in Packaging your application source code with RPM:

    FROM quay.io/fedora/fedora:40
    
    COPY my_repo /tmp/my_repo
    
    RUN ls -l /tmp && ls -l /tmp/my_repo
    
    RUN dnf install -y /tmp/my_repo/x86_64/auto-apps-0.1*.rpm && dnf clean all
    
  2. Copy the RPM repository from /var/tmp/my_repo to the same directory where you have created the Containerfile file:

    $ cp -r /var/tmp/my_repo .
    
  3. Run podman build in the same directory as your Containerfile to build the container image, and name the container image auto-apps:

    $ sudo podman build -t localhost/auto-apps:latest -f Containerfile
    
  4. Start a container from your auto-apps container image,

    $ sudo podman run -it auto-apps
    
  5. From within the running container, verify that your RPM package is present.

    $ rpm -q auto-apps
    

    If the auto-apps RPM was embedded successfully in the container, the output of the rpm -q command displays the version of your package:

    $ auto-apps-0.1-1.fc40.x86_64
    

Now that you have a functional auto-apps container image, you can embed your containerized applications in the OS image with OSBuild.

Next steps

After creating a container image for your application, you can embed it in an OS image.

Depending on your needs, you can use one of two methods to embed the container image in your operating system image:

  • Recommended method: Create the container image and add it to a remote container registry.Then, pull the container image from the remote registry to include in the OS image. This method is the only reliable, reproducible method for OS image builds and is therefore recommended.
  • Development method: Create the container image and add it to a local RPM repository. Then, pull the container image from your local repository to include in the OS image. Only use this method to build OS images for development and experimentation purposes.

© Red Hat