How to Install Buildah OCI on Ubuntu 20.04 or 22.04 LTS

Install Buildah on Ubuntu 22.04 Jammy JellyFish or Ubuntu 20.04 Focal Fossa Linux using the command terminal to create container images from their source codes.

In today’s fast-paced world, developers need a mechanism to deploy their apps as fast as they can and keep them up to date as well. This is the reason why containerized applications are becoming more and more important and to create containers automatically, images are needed. These can be created with Buildah.

Let’s see what technically Buildah is?

Buildah is an open source tool originally developed by Red Hat. It helps developers build container images for containers built for Docker/Kubernetes environments using their source code. Images created by Buildah can even be used for other container services such as Podman. One of the advantages of Buildah is that there is no overhead in creating images.

Buildah facilitates the creation of Open Container Initiative (OCI) container images that continue to advance the possibilities of containers. It is therefore important to comply with the standards set by the OIC. This allows tools to be shared, even if they were programmed by different developers. This is interesting for a combination of Podman with Buildah.

By using Buildah after installation with Podam or Docker, the following things can be done without the need for any additional tools.

⇒ Create images in traditional Docker image or OCR image format.
⇒ Create new containers from different sources.
⇒ Using a working container or from a Dockerfile, images can be created for containers.
⇒ Use the updated contents of a container’s root filesystem as a filesystem layer to create a new image.
⇒ Renaming a local container.
⇒ Delete system images.

You can find on GitHub how use the Buildah with examples. An example of creating an image with Buildah can also be found at GithubGenericName.

Steps to Install and Use Buildah on Ubuntu 22.04 or 20.04

1. Update Ubuntu

Buildah packages are available through the standard repository, so run the system update command first. This will rebuild the APT package manager index cache and also install the latest update, if available.

sudo apt update && sudo apt upgrade

2. Install Buildah on Ubuntu 20.04 or 22.04

To install the open source Buildah tool, we don’t need to add any third-party repository. As I told you earlier, we can use the APT package manager and the standard repository to install this container imaging tool, so let’s do that.

sudo apt install buildah

To check the version, use:

buildah -v

3. Use Buildah to create a container

Once the installation is complete, we can use Buildah to extract and create a container image. For example, let’s get the Almalinux image to build it according to our needs.

buildah from almalinux

Now we have the Almalinux image on our system. Let’s install the apps we want on our pre-installed image before running it in a container. For example, we want an AlmaLinux image with an Httpd server preinstalled. So, for this, we can follow the given steps.

The default image name of the one pulled by Buildah – almalinux-working-container will be flashed to your terminal after extracting the image.

Run the system update for the image:

buildah run almalinux-working-container dnf update

Let’s install the Apache web server in the created container

buildah run almalinux-working-container dnf install httpd -y

install apache in buildah image

After that, set HTTPd as the entry point, so it can automatically start in the background when we run the container.

buildah config --entrypoint "/usr/sbin/httpd -DFOREGROUND" almalinux-working-container

4. Create an image

Once you’ve added everything you want in your stuff, like we added the Apache web server, it’s time to create a new image with the changes made.

buildah commit almalinux-working-container myfirstimage

In the command above almalinux-working-container is the name given to the container created using an image pulled by Buildah and myfirstimage is the name in which we want to save the image created using the container for our use.

5. Run the image created by Buildah with Podamn or Docker

Once we have our own custom image created using Buildah, we can create a container using that image.

First let’s check whether the image is available or not. Here we use Podman.

podman images

Build your image using the Buildah container

6. Create and run a container using your image

After creating an image, we can use it to create our container using Podman or Docker. Here is the command for it.

podman create --name demo myfirstimage

myfirstimage is the name of the image we created, you can use your own.

demo is the name we gave to our container, you can use whatever you want.

To note: if you want to expose the port for the container to access its running service from outside, mention it in the command when creating the container.

Start the container:

podman start demo

To change at the command line of your started container:

podman exec -it demo /bin/bash

Now we can execute the commands we want.

To note: If you get an error while running the update command in your container, here is the solution.

Error: Failed to download metadata for repository ‘appstream’: unable to prepare internal mirror list: no url in mirror list

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
sudo dnf update -y

To learn more about using Podman and Buildah, see the Red Hat Guide.

Other Items:

How to Install Podman on Rocky Linux 8 / AlmaLinux
Install Miniconda on Ubuntu 22.04 LTS
How to Install Emacs 28 on Ubuntu 20.04…
Install DaVinci Resolve on Ubuntu 22.04…


Source link

Steven L. Nielsen