1. Containerize Your First Application
1. Containerize Your First Application ๊ด๋ จ
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.
buildah run ubi-working-container -- dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
# Updating Subscription Management repositories.
# Unable to read consumer identity
# Subscription Manager is operating in container mode.
#
# This system is not registered with an entitlement server. You can use subscription-manager to register.#
#
# Red Hat Universal Base Image 9 (RPMs [=== ] --- B/s | 0 B --:-- ETA#
# Red Hat Universal Base Image 9 (RPMs) - BaseOS 1.6 MB/s | 509 kB 00:00 #
# Red Hat Universal Base Image 9 (RPMs) - AppStream 3.4 MB/s | 1.7 MB 00:00 #
# Red Hat Universal Base Image 9 (RPMs) - CodeReady Builder 745 kB/s | 187 kB 00:00 #
# epel-release-latest-9.noarch.rpm 37 kB/s | 19 kB 00:00 #
# Dependencies resolved.#
# ==============================================================================================================# =
# Package Architecture Version Repository Size#
# ==============================================================================================================# =
# epel-release noarch 9-7.el9 @commandline 19 k#
# Installing:#
#
# Installing weak dependencies:#
# dnf-plugins-core noarch 4.3.0-5.el9_2 ubi-9-baseos-rpms 42 k# Transaction Summary
#
#
# ===============================================================================================================
# Install 2 Packages
# Total download size: 42 k
# Total size: 60 k
# Downloading Packages:
# Installed size: 48 k#
# --------------------------------------------------------------------------------# -------------------------------
# dnf-plugins-core-4.3.0-5.el9_2.noarch.rpm 4# 65 kB/s | 42 kB 00:00
# Running transaction check#
# Total 4# 53 kB/s | 42 kB 00:00
# Running transaction test#
# Transaction check succeeded.#
# Running transaction#
# Transaction test succeeded.#
# Installing : dnf-plugins-core-4.3.0-5.el9_2.noarch # 1/2 #
# Preparing : # 1/1 #
# Running scriptlet: epel-release-9-7.el9.noarch # 2/2 #
# Installing : epel-release-9-7.el9.noarch # 2/2 #
#
# Many EPEL packages require the CodeReady Builder (CRB) repository.#
# It is recommended that you run /usr/bin/crb enable to enable the CRB repository.# Verifying : dnf-plugin# s-core-4.3.0-5.el9_2.noarch 1/2
#
#
# Verifying : epel-release-9-7.el9.noarch 2/2 #
# Installed products updated.#
#
# Installed:
# dnf-plugins-core-4.3.0-5.el9_2.noarch epel-release-9-7.el9.noarch
#
# Complete!
This command runs the command
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)
dnf -y install --skip-broken https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
# Waiting for process with pid 69209 to finish.
# Last metadata expiration check: 0:23:58 ago on Wed 13 Sep 2023 05:39:51 AM UTC.
# epel-release-latest-9.noarch.rpm 47 kB/s | 19 kB 00:00
# Dependencies resolved.
# Nothing to do.
# Complete!
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:
buildah run ubi-working-container -- dnf -y install moon-buggy
# Updating Subscription Management repositories.
# Unable to read consumer identity
# Subscription Manager is operating in container mode.
#
# This system is not registered with an entitlement server. You can use subscription-manager to register.
#
# Extra Packages for Enterprise Linux 9 - x86_64 19 MB/s | 19 MB 00:00
# Extra Packages for Enterprise Linux 9 openh264 (From Cisco) - x86_64 2.1 kB/s | 2.5 kB 00:01
# Dependencies resolved.
# ===============================================================================================================
# Package Architecture Version Repository Size
# ===============================================================================================================
# Installing:
# moon-buggy x86_64 1.0.51-30.el9 epel 79 k
# Installing dependencies:
# alsa-lib x86_64 1.2.8-3.el9 ubi-9-appstream-rpms 521 k
# audiofile x86_64 1:0.3.6-30.el9 epel 131 k
# esound-libs x86_64 1:0.2.41-27.el9 epel 75 k
# flac-libs x86_64 1.3.3-10.el9_2.1 ubi-9-appstream-rpms 221 k
# libogg x86_64 2:1.3.4-6.el9 ubi-9-appstream-rpms 36 k
#
# Transaction Summary
# ===============================================================================================================
# Install 6 Packages
#
# Total download size: 1.0 M
# Installed size: 2.7 M
# Downloading Packages:
# (1/6): esound-libs-0.2.41-27.el9.x86_64.rpm 406 kB/s | 75 kB 00:00
# (2/6): audiofile-0.3.6-30.el9.x86_64.rpm 684 kB/s | 131 kB 00:00
# (3/6): moon-buggy-1.0.51-30.el9.x86_64.rpm 384 kB/s | 79 kB 00:00
# (4/6): libogg-1.3.4-6.el9.x86_64.rpm 179 kB/s | 36 kB 00:00
# (5/6): alsa-lib-1.2.8-3.el9.x86_64.rpm 2.2 MB/s | 521 kB 00:00
# (6/6): flac-libs-1.3.3-10.el9_2.1.x86_64.rpm 951 kB/s | 221 kB 00:00
# ---------------------------------------------------------------------------------------------------------------
# Total 1.2 MB/s | 1.0 MB 00:00
# Extra Packages for Enterprise Linux 9 - x86_64 1.6 MB/s | 1.6 kB 00:00
# Importing GPG key 0x3228467C:
# Userid : "Fedora (epel9) <epel@fedoraproject.org>"
# Fingerprint: FF8A D134 4597 106E CE81 3B91 8A38 72BF 3228 467C
# From : /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-9
# Key imported successfully
# Running transaction check
# Transaction check succeeded.
# Running transaction test
# Transaction test succeeded.
# Running transaction
# Preparing : 1/1
# Installing : libogg-2:1.3.4-6.el9.x86_64 1/6
# Installing : flac-libs-1.3.3-10.el9_2.1.x86_64 2/6
# Installing : audiofile-1:0.3.6-30.el9.x86_64 3/6
# Installing : alsa-lib-1.2.8-3.el9.x86_64 4/6
# Installing : esound-libs-1:0.2.41-27.el9.x86_64 5/6
# Installing : moon-buggy-1.0.51-30.el9.x86_64 6/6
# Running scriptlet: moon-buggy-1.0.51-30.el9.x86_64 6/6
# Verifying : audiofile-1:0.3.6-30.el9.x86_64 1/6
# Verifying : esound-libs-1:0.2.41-27.el9.x86_64 2/6
# Verifying : moon-buggy-1.0.51-30.el9.x86_64 3/6
# Verifying : alsa-lib-1.2.8-3.el9.x86_64 4/6
# Verifying : libogg-2:1.3.4-6.el9.x86_64 5/6
# Verifying : flac-libs-1.3.3-10.el9_2.1.x86_64 6/6
# Installed products updated.
#
# Installed:
# alsa-lib-1.2.8-3.el9.x86_64 audiofile-1:0.3.6-30.el9.x86_64 esound-libs-1:0.2.41-27.el9.x86_64
# flac-libs-1.3.3-10.el9_2.1.x86_64 libogg-2:1.3.4-6.el9.x86_64 moon-buggy-1.0.51-30.el9.x86_64
#
# Complete!
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