RHCSA Practical Lab Series – Building a Container Image with Podman

Expertise in Cloud, Networking & DevOps
Photo by Lucas K / Unsplash

πŸ” Lab 13: Creating a Custom Container Image

πŸ“Œ Objective

In this lab, you will:

βœ” Install Podman and required container tools
βœ” Download a Containerfile and build a container image
βœ” Ensure the image is named appserver
βœ” Verify the created image


πŸ“Œ Step 1: Install Container Management Tools

πŸ”Ή Ensure container-tools is installed:

[root@node1 ~]# dnf -y install container-tools

πŸ“Œ Explanation:

  • Installs Podman and other required tools for container management.
  • The -y flag automatically confirms installation.

βœ… Once installed, proceed to Step 2.


πŸ“Œ Step 2: Switch to devops User

πŸ”Ή Log in as devops to manage containers:

[root@node1 ~]# ssh devops@node1

πŸ“Œ Why? Running containers as a non-root user improves security in production environments.

βœ… If successfully logged in, the prompt should change to [devops@node1 ~]$.


πŸ“Œ Step 3: Authenticate with the Container Registry

πŸ”Ή Log in to the container registry to pull and push images:

[devops@node1 ~]$ podman login -u admin -p SecurePass123 registry.cloudnetops.tech

πŸ“Œ Explanation:

  • podman login β†’ Authenticates with a container registry.
  • -u admin β†’ Uses admin as the username.
  • -p SecurePass123 β†’ Password for authentication.
  • registry.cloudnetops.tech β†’ The container registry URL.

βœ… If login is successful, proceed to Step 4.


πŸ“Œ Step 4: Download the Containerfile

πŸ”Ή Retrieve the Containerfile from the remote server:

[devops@node1 ~]$ wget http://classroom/Containerfile

πŸ“Œ Explanation:

  • wget β†’ Downloads files from a remote server.
  • http://classroom/Containerfile β†’ The URL hosting the Containerfile.

βœ… Once downloaded, you should see a file named Containerfile in the current directory.


πŸ“Œ Step 5: Build the Container Image

πŸ”Ή Use Podman to build the image and tag it as appserver:

[devops@node1 ~]$ podman build -t appserver .

πŸ“Œ Explanation:

  • podman build β†’ Builds a container image from a Containerfile.
  • -t appserver β†’ Tags the image as appserver.
  • . β†’ Uses the current directory as the build context.

βœ… If the build succeeds, the image is now stored locally.


πŸ“Œ Step 6: Verify the Built Image

πŸ”Ή List available images to confirm the build:

[devops@node1 ~]$ podman images

πŸ“Œ Expected Output:

REPOSITORY                           TAG      IMAGE ID       CREATED         SIZE
localhost/appserver                  latest   3f4b1e2c1a56   2 minutes ago   125MB

βœ… If appserver appears in the list, the image was built successfully.

πŸ”Ή Inspect the image details:

[devops@node1 ~]$ podman inspect appserver

πŸ“Œ Step 7: Run and Test the Container (Optional)

πŸ”Ή Run the newly built container to test its functionality:

[devops@node1 ~]$ podman run -d --name test_app -p 8080:80 appserver

πŸ“Œ Explanation:

  • -d β†’ Runs the container in detached mode.
  • --name test_app β†’ Assigns a name to the running container.
  • -p 8080:80 β†’ Maps port 8080 on the host to port 80 in the container.
  • appserver β†’ Uses the newly built image.

πŸ”Ή Check if the container is running:

[devops@node1 ~]$ podman ps

πŸ“Œ Expected Output:

CONTAINER ID  IMAGE       COMMAND  CREATED        STATUS        PORTS       NAMES
a1b2c3d4e5f6  appserver   ...      10 seconds ago  Up 5 seconds  8080->80/tcp test_app

βœ… If the container is running, it was successfully deployed!


βœ… Final Summary

βœ” Installed Podman and container tools
βœ” Logged in as a non-root user (devops)
βœ” Pulled a Containerfile and built an image (appserver)
βœ” Verified the image and tested container execution


πŸ“Œ Next Lab: Running a Container as a Systemd Service

πŸ“© Subscribe for more RHCSA exam labs and hands-on tutorials! πŸš€


Read more