RHCSA Practical Lab Series β Building a Container Image with Podman
π 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
β Usesadmin
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 asappserver
..
β 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! π