- Lab
-
Libraries: If you want this lab, consider one of these libraries.
- Cloud
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.
Lab 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:latestcontainer image - Maintainer=“[email protected]”
- Install
httpdin 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
httpdservice 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 budto 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:latestcontainer image. - Maintainer=
[email protected]” - Install
httpdin 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
httpdservice 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_userhome 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
helpinformation for thebuildahcommand.- View the
helpinformation for thebuildah helpcommand.
- View the
- View the
manpage for thebuildahcommand. - Display information for the
buildahsystem. - Diplay information about the
localhost/my-fedora-httpdcontainer image. - Check the version of
buildah.
Content Management Using Buildah:
Perform the following:
- Create a directory
~/testfilesand add some test files to it using thefor i inseq 1 5; do echo "Add Test File "$i > ~/testfiles/add$i.txt ; echo "Copy Test File "$i > ~/testfiles/copy$i.txt ; donecommand.- View the contents of the files to verify them.
- View the
helpinformation for thebuildah addandbuildah copycommands. - Create a new intermediate container using the
fedora:latestcontainer image. - Use
buildahto 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).txtfiles usingbuildah addcommand. - Transfer the
copy(1-5).txtfiles using thebuildah copycommand.
- 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
buildahto 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:latestcontainer 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:latestcontainer image from our local storage (not the local container registry!). - List our local container images using
buildahagain. - Pull the
localhost/my-fedora-httpd:latestcontainer image from the local container registry. - List our local container images using
buildahagain. - Add a tag for our
my-fedora-httpd:latestimage.- Make the tag
ourcustomwebserver:latest.
- Make the tag
- List our local container images using
buildahagain. - Log out of our local container image registry.
Container Management Using Buildah:
Perform the following:
- Diplay a list of containers using
buildah. - Use
buildahto rename the intermediate working container tomy-container. - Diplay a list of containers using
buildahagain. - Remove the
my-containercontainer usingbuildah. - Diplay a list of containers using
buildahagain.
Great work, Cloud Gurus!
- View the
About the author
Real skill practice before real-world application
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.
Learn by doing
Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.
Follow your guide
All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.
Turn time into mastery
On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.