Page
Prerequisites and step-by-step process
Prerequisites:
- Register with a no-cost Red Hat Developer subscription. Register if not already registered.
- Podman is installed on your laptop. Download Podman here.
Step-by-step guide:
1. Register your system with Red Hat Subscription Management and attach your system with the Red Hat subscription
To get the full benefits of a Red Hat subscription, you must register your system with the Red Hat Subscription Manager and attach the subscription to it. Follow the instructions below to register your system with the Red Hat Subscription Manager. Ensure you execute the following commands on your local machine.
Use the following command to register the system, then automatically associate any available subscription matching that system:
# subscription-manager register --username <username> --password <password> --auto-attach
Use the following command to register a system without immediately attaching a subscription:
# subscription-manager register
After this, refresh the information on your machine using the following command:
# subscription-manager refresh
After registration, use the following command to attach any available subscription that matches the current system.
# subscription-manager attach --auto
After registration, use the following command to attach a subscription from a specific pool: Get the available pool-ids -
# subscription-manager list --available
Then select specific pool-id :
# subscription-manager attach --pool=
Add specific repositories for RHEL 9 with your subscription.
# subscription-manager repos --enable=rhel-9-for-x86_64-baseos-rpms --enable=rhel-9-for-x86_64-appstream-rpms
# dnf update
2. Create a bootable image mode for RHEL based container file and build using Podman
Learn how to get the rhel-bootc base image from the registry and create a container file. Build container image using Podman commands.
This step will walk you through a simple installation of Podman on your laptop, pulling the rhel-bootc base image from Red Hat Registry and creating a sample container file.
Install Podman on your laptop. Create and build container file using Podman
Podman is a Linux native tool designed to build, run and deploy OCI-compliant containers. To Install Podman on your laptop:
- Download Podman on your computer for your specific OS ( Windows, Linux, Mac) :
https://podman.io/docs/installation After installing Podman, log in to registry.redhat.io using the podman CLI command with the following syntax:
$ podman login registry.redhat.io
Verify the availability of rhel-bootc image from catalog.redhat.com
$ podman pull registry.redhat.io/rhel9/rhel-bootc:9.4
Write a container file/docker file to get a bootc-based RHEL Image Mode image. The container file will have layers for getting the bootc image, installing the application's requirement components, and starting services and the application. File name given is - containerfile. You can copy below command directly on terminal to create a container file.
cat <<EOF >>containerfile FROM registry.redhat.io/rhel9/rhel-bootc #install the lamp components RUN dnf module enable -y php:8.2 nginx:1.22 && dnf install -y httpd mariadb mariadb-server php-fpm php-mysqlnd && dnf clean all #start the services automatically on boot RUN systemctl enable httpd mariadb php-fpm #create an awe inspiring home page! RUN echo '<h1 style="text-align:center;">Welcome to RHEL image mode</h1> <?php phpinfo(); ?>' EOF
Build the container image using the provided "containerfile" with Podman. Ensure that you execute the following command in the same directory where the "containerfile" is located. Replace the [my_account] with your Quay.io account username.
$ podman build -f containerfile -t quay.io/[my_account]/lamp-bootc:latest
Info alert:
-t
will tag the image. This example assumes that quay.io is the registry being used.-f
will instruct Podman to use Container file created in step before. .Now that we have our image, let’s test it really quick. Since our image is a container, it’s fast to run and verify if we have any typos, as an error will be emitted. We’ll give it the short name (lamp) for simplicity:
$ podman run -d --rm --name lamp -p 8080:80 quay.io/[my_account]/lamp-bootc:latest /sbin/init
The container will start. In this example, we’re starting systemd.
- Open a browser locally and verify that you can view the webpage being served at http://[your_ip_address]:8080. If the page doesn’t load, double-check your firewall rules if you are using the remote system to connect. The loopback address should work fine if you’re using a local system. In this example, we’re starting systemd.
Now that the image is ready let's push it to the registry and configure the repository to be publicly accessible.
$ podman login quay.io $ podman push quay.io/[my_account]/lamp-bootc:latest
Log in to your Quay.io container registry. Once logged in, you will see the image listed in your account, as shown in the following image.
Summary
We have walked you through a simplistic example that shows how easy it is to create a bootable container image with image mode for RHEL and run it locally.
At this point, we have created a layered image that we can deploy. There are several ways to install it on a host: We can use RHEL’s installer and kickstart a bare metal system (deploy via USB, PXE, etc.). Note that once this container is “installed,” future updates will apply directly from the container registry as they are published. So, the installation process only happens once.