- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
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.
- Based on the
-
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
.
- Contents should be
- 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.
- Based on the
-
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 thecloud_user
home directory. You will need to run this script withsudo
, as it requires root privilages. -
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 thebuildah
command.- View the
help
information for thebuildah help
command.
- View the
- View the
man
page for thebuildah
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 thefor i in
seq 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 thebuildah add
andbuildah 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 usingbuildah add
command. - Transfer the
copy(1-5).txt
files using thebuildah copy
command.
- Transfer the
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.
- Use
- 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 athttps://localhost:5000
.- Username:
cloud_user
- Password: Enter the password provided by the lab credentials.
- Username:
- 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
.
- Make the tag
- 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 tomy-container
. - Diplay a list of containers using
buildah
again. - Remove the
my-container
container usingbuildah
. - Diplay a list of containers using
buildah
again.
Great work, Cloud Gurus!
- View the
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.