Customizing Container Images Using Podman and Buildah on RHEL

1 hour
  • 4 Learning Objectives

About this Hands-on Lab

An important part of the Podman landscape is container images, and the Podman team have provided Buildah to create those images. In this lab, we will use Buildah to create our own custom container images using both a Dockerfile and native Buildah commands. We will also take a look at some of Buildah’s container image management functionality. Upon completion of this lab, you will be able to use Buildah to create your own custom container images.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Container Image Using Buildah a Dockerfile

We’re going to use the following criteria to build a custom container image, using Buildah and a Dockerfile:

  • Based on the fedora:latest container image
  • Maintainer=“buildah@podman.rulez”
  • Install httpd in the container
    • Clean up after install
  • Create five test text files in /var/www/html
    • Contents should be "Test File (1-5)"
    • Filenames should be "test(1-5).txt"
  • Expose port 80
  • Run our httpd service using "/usr/sbin/httpd -D FOREGROUND"
  • Name our image my-fedora-httpd:latest

Instructions:

First create a Dockerfile based on the above criteria, then use buildah bud to build a container image from the Dockerfile. Next, launch five containers `my-fedora-httpd-(1-5) and test with curl. Make sure you can retrieve any of the test files (test(1-5).txt) from any of the containers.

When testing is successful, clean up all your containers and images.

Create a Container Image Using Buildah Native Commands

We’re going to use the following criteria to build a custom container image, using Buildah Native Commands:

  • Based on the fedora:latest container image
  • Maintainer=“buildah@podman.rulez”
  • Install httpd in the container
    • Clean up after install
  • Create five test text files in /var/www/html
    • Contents should be "Test File (1-5)"
    • Filenames should be "test(1-5).txt"
  • Expose port 80
  • Run our httpd service using "/usr/sbin/httpd -D FOREGROUND"
  • Name our image my-fedora-httpd:latest

Instructions:

Build a container image using the above description using buildah native commnads. Next, launch five containers `my-fedora-httpd-(1-5) and test with curl. Make sure you can retrieve any of the test files (test(1-5).txt) from any of the containers.

Start the Local Container Image Registry

A local container image registry has been pre-configured on your server. Before we can use it, we need to start it. A script (registry.sh) has been provided in the cloud_user home directory. You will need to run this script with sudo, as it requires root privilages.

Use Buildah to Manage Containers and Images

Let’s explore the ways we can manage containers and images using buildah!

General Buildah Commands:

Perform the following:

  • View the help information for the buildah command
    • View the help information for the buildah help command
  • View the man page for the buildah command
  • Display information for the buildah system
  • Diplay information about the localhost/my-fedora-httpd container image
  • Check the version of buildah

Content Management Using Buildah:

Perform the following:

  • Create a directory ~/testfiles and add some test files to it using the for i inseq 1 5; do echo "Add Test File "$i > ~/testfiles/add$i.txt ; echo "Copy Test File "$i > ~/testfiles/copy$i.txt ; done command
    • View the contents of the files to verify them
  • View the help information for the buildah add and buildah copy commands
  • Create a new intermediate container using the fedora:latest container image
  • Use buildah to list its containers
  • Transfer the files you created into the /var/www/html/ directory of the intermediate container you created
    • Transfer the add(1-5).txt files using buildah add command
    • Transfer the copy(1-5).txt files using the buildah copy command

Filesystem Management Using Buildah:

Perform the following:

  • Run your commands using a modified user namespace
  • Mount the intermediate container’s filesystem
  • Check for our newly transferred files
    • Use ls
    • View the contents of the files
  • Unmount the intermediate container’s filesystem
  • Exit the modified user namespace

Image Management Using Buildah:

Perform the following:

  • List our container images using buildah
  • Use buildah to log in to our local container registry at https://localhost:5000
    • Username: cloud_user
    • Password: registry
  • Push our localhost/my-fedora-httpd:latest container image to the local container registry
  • Check our work using curl -u cloud_user:registry https://localhost:5000/v2/_catalog
  • List our local container images using buildah
  • Remove the localhost/my-fedora-httpd:latest container image from our local storage (not the local container registry!)
  • List our local container images using buildah again
  • Pull the localhost/my-fedora-httpd:latest container image from the local container registry
  • List our local container images using buildah again
  • Add a tag for our my-fedora-httpd:latest image
    • Make the tag ourcustomwebserver:latest
  • List our local container images using buildah again
  • Log out of our local container image registry

Container Management Using Buildah:

Perform the following:

  • Diplay a list of containers using buildah
  • Use buildah to rename the intermediate working container to my-container
  • Diplay a list of containers using buildah again
  • Remove the my-container container using buildah
  • Diplay a list of containers using buildah again

Great work, Cloud Gurus!

Additional Resources

Let's build some container images!

We're going to build our own custom Apache container image, based on the fedora:latest image, and add some custom test files. We'll try our hand at building the container image from both a Dockerfile and by using Buildah Native Commands. Once we have our new container image, we will start some containers from it and test our work. Finally, we'll use buildah to manage our build containers and images.

Onward!

When the lab starts, you will want to open an SSH connection to your lab instance(s):

ssh cloud_user@PUBLIC_IP_ADDRESS

Replace PUBLIC_IP_ADDRESS with either the public IP or DNS of the instance(s). The 'cloud_user' password has been provided with the instance information.

Good luck and enjoy!

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?