Skip to main content

1. Containerize Your First Application

About 4 minRedHatcrashcourseredhatbuildahpodmanskopeosesearchsemodule

1. Containerize Your First Application ๊ด€๋ จ


Containerize Your Application With Buildah And Podman

Intro

Starting with Moon-Buggy Game

Step 1

To start containerizing our Application (Moon-buggy), we'll first create a new container using the UBI9 image as the base.

buildah from registry.access.redhat.com/ubi9/ubi
# Trying to pull registry.access.redhat.com/ubi9/ubi:latest...
# Getting image source signatures
# Checking if image destination supports signatures
# Copying blob 3b7adf049118 done  
# Copying config 9f43f297e7 done  
# Writing manifest to image destination
# Storing signatures
# ubi-working-container

This command will pull the UBI9 image from the Red Hat registry and create a new container using it as the base.

Buildah appends -working-container to indicate working containers (default).

Step 2

Install EPEL repository to container for access to extra packages on Red Hat-based distributions.

Script
buildah run ubi-working-container -- dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm

This command runs the command

Script (Failed)
dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
# Last metadata expiration check: 0:23:19 ago on Wed 13 Sep 2023 05:39:51 AM UTC.
# epel-release-latest-9.noarch.rpm                                                45 kB/s |  19 kB     00:00    
# Error: 
#  Problem: conflicting requests
#   - nothing provides redhat-release >= 9 needed by epel-release-9-7.el9.noarch
# (try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

inside the container, ubi-working-container. This installs the EPEL repository to the container.

Step 3

To install the Moon-buggy package, we'll run the following command after installing the EPEL repository:

Script
buildah run ubi-working-container -- dnf -y install moon-buggy

Step 4

To save changes made to the container and create a new deployable image, run the following command:

buildah commit ubi-working-container moon-buggy
# Getting image source signatures
# Copying blob c662a0c69917 skipped: already exists  
# Copying blob 7eb0760619fd done  
# Copying config 1a9a935c5a done  
# Writing manifest to image destination
# Storing signatures
# 1a9a935c5a439a39ae99469be8644aa1e3af79ad8917f70b620e6cd50b36f507

This command takes the current state of the container ubi-working-container and creates a new image with the name moon-buggy.

This new image contains everything that was installed and configured in the running container

Step 5

Now that we have the final image of our moon-buggy game, we can check for the image using the following command:

podman image list
# REPOSITORY                           TAG         IMAGE ID      CREATED         SIZE
# localhost/moon-buggy                 latest      1a9a935c5a43  21 seconds ago  296 MB
# registry.access.redhat.com/ubi9/ubi  latest      9f43f297e77b  7 days ago      217 MB

Step 6

Once we confirm that the image moon-buggy is present, we can use the following command to start a new container from the image and play the game:

podman run --name moon-buggy -it moon-buggy /usr/bin/moon-buggy

์ด์ฐฌํฌ (MarkiiimarK)
Never Stop Learning.