Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Customizing Container Images Using Podman and Buildah on RHEL

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 15m
Published
Clock icon Apr 23, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create a Container Image Using Buildah and 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=“[email protected]
    • 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.

  2. Challenge

    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=[email protected]
    • 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.

  3. Challenge

    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.

  4. Challenge

    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: Enter the password provided by the lab credentials.
    • 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!

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans