RHCSA9 EXAM SERIES: Manage Containers

RHCSA 9 Container Management Skills

Looking to enhance your Linux skillset? RHCSA 9 Container Management Skills introduces a new section on container management, making it a must-have competency for any aspiring Linux professional. Develop the skills and knowledge needed to manage containers using various tools and commands with ease.

Table of Contents

Introduction

As the world shifts towards containerized applications, managing containers has become an essential skill for Linux professionals. Red Hat Certified System Administrator (RHCSA) 9 exam has introduced a new section on container management, which focuses on managing containers using various tools and commands. In this article, we will discuss the “Manage Containers” section of the RHCSA 9 exam and provide examples of how to perform various container management tasks.

Finding and Retrieving Container Images from a Remote Registry Container images are the building blocks of containers. Before running a container, we need to have an image of it. In the RHCSA 9 exam, candidates will be required to find and retrieve container images from a remote registry. The most commonly used container registry is Docker Hub. The following commands can be used to retrieve a container image from a remote registry
RHCSA 9 Container Management Skills

Photo by Tom Fisk from Pexels

RHCSA 9 Container Management Skills: Docker vs. Podman

Using Docker CLI

				
					$ docker pull <image-name>
				
			

For example, to pull the latest version of the Nginx web server image, we can use the following command:

				
					$ docker pull nginx:latest
				
			

Using Podman CLI

				
					$ podman pull <image-name>
				
			

For example, to pull the latest version of the Nginx web server image using Podman, we can use the following command:

				
					$ podman pull docker.io/library/nginx:latest
				
			

Inspecting Container Images

Before running a container, it is important to inspect its image to ensure that it is the correct version and that it meets all the requirements. The following commands can be used to inspect a container image:

Using Docker CLI

				
					$ docker inspect <image-name>
				
			

For example, to inspect the Nginx web server image, we can use the following command:

				
					$ docker inspect nginx:latest
				
			

Using Podman CLI

				
					$ podman inspect <image-name>
				
			

For example, to inspect the Nginx web server image using Podman, we can use the following command:

				
					$ podman inspect docker.io/library/nginx:latest
				
			

Performing Container Management

Using Commands Such as Podman and Skopeo Podman and Skopeo are command-line tools that can be used for container management. They are alternatives to Docker CLI and can perform most of the same tasks. The following commands can be used to perform container management using Podman and Skopeo:

Using Podman CLI

				
					$ podman ps # List running containers
				
			
				
					$ podman run <image-name> # Run a container
				
			
				
					$ podman stop <container-id> # Stop a container
				
			

For example, to list all running containers using Podman, we can use the following command:

				
					$ podman ps
				
			

Using Skopeo CLI

				
					$ skopeo copy <source-image> <destination-image> # Copy an image from one registry to another
				
			
				
					$ skopeo inspect <image-name> # Inspect an image
				
			

For example, to copy an image from Docker Hub to Red Hat Quay using Skopeo, we can use the following command:

				
					$ skopeo copy docker://nginx:latest docker://quay.io/my-repo/nginx:latest
				
			

Building a Container from a Containerfile

A Containerfile is a text file that contains instructions for building a container image. The following commands can be used to build a container from a Containerfile:

Using Docker CLI

				
					$ docker build -t <image-name> <path-to-Containerfile>
				
			

For example, to build a container image of Nginx web server from a Containerfile, we can use the following command:

				
					$ docker build -t nginx-web-server:latest .
				
			

Using Podman CLI

				
					$ podman build -t <image-name> <path-to-Containerfile>
				
			

For example, to build a container image of Apache web server from a Containerfile, we can use the following command:

				
					$ podman build -t apache-web-server:latest .
				
			

RHCSA 9 Container Management Skills

In this section, we’ll review performing basic container management such as running, starting, stopping, and listing containers.

Running Containers

Basic container management involves tasks such as running, starting, stopping, and listing running containers. The following commands can be used to perform basic container management tasks:

Using Docker CLI

				
					$ docker run <image-name> # Run a container
				
			
				
					$ docker start <container-id> # Start a stopped container
				
			
				
					$ docker stop <container-id> # Stop a running container
				
			
				
					$ docker ps # List running containers
				
			

For example, to run a container of Ubuntu Linux using Docker CLI, we can use the following command:

				
					$ docker run ubuntu:latest
				
			

Using Podman CLI

				
					$ podman run <image-name> # Run a container
				
			
				
					$ podman start <container-id> # Start a stopped container
				
			
				
					$ podman stop <container-id> # Stop a running container
				
			
				
					$ podman ps # List running containers
				
			

For example, to run a container of CentOS Linux using Podman CLI, we can use the following command:

				
					$ podman run centos:latest
				
			

Running a Service Inside a Container

Containers are often used to run services such as web servers, databases, and messaging brokers. The following commands can be used to run a service inside a container:

Using Docker CLI

				
					$ docker run --name <container-name> -d <image-name> <service-command>
				
			

For example, to run a MySQL database server inside a Docker container, we can use the following command:

				
					$ docker run --name mysql-server -d mysql:latest
				
			

Using Podman CLI

				
					$ podman run --name <container-name> -d <image-name> <service-command>
				
			

For example, to run a PostgreSQL database server inside a Podman container, we can use the following command:

				
					$ podman run --name postgresql-server -d postgres:latest
				
			

Configuring a Container to Start Automatically as a Systemd Service

Systemd is a system and service manager for Linux operating systems. It can be used to manage containers as well. The following commands can be used to configure a container to start automatically as a systemd service:

Using Docker CLI

				
					$ docker run --name <container-name> -d <image-name> <service-command>
				
			
				
					$ docker update --restart=always <container-name>
				
			

For example, to configure a Docker container running the Nginx web server to start automatically as a systemd service, we can use the following commands:

				
					$ docker run --name nginx-server -d nginx:latest
				
			
				
					$ docker update --restart=always nginx-server
				
			

Using Podman CLI

				
					$ podman generate systemd <container-name> -n # Generate systemd unit file for the container
				
			
				
					$ systemctl enable <container-name>.service # Enable and start the container as a systemd service
				
			

For example, to configure a Podman container running the Apache web server to start automatically as a systemd service, we can use the following commands:

				
					$ podman generate systemd apache-server -n
				
			
				
					$ systemctl enable apache-server.service
				
			

RHCSA 9 Container Management Skills: Storage Management

Attaching Persistent Storage to a Container

Persistent storage is important for applications that require data to be stored between container restarts. The following commands can be used to attach persistent storage to a container:

Using Docker CLI

				
					$ docker run --name <container-name> -v <host-path>:<container-path> <image-name> <service-command>
				
			

For example, to attach a persistent storage volume to a Docker container running the MariaDB database server, we can use the following command:

				
					$docker run --name mariadb-server -v /opt/mariadb-data:/var/lib/mysql -d mariadb:latest
				
			

Using Podman CLI

				
					$ podman run --name <container-name> -v <host-path>:<container-path> <image-name> <service-command>
				
			

For example, to attach a persistent storage volume to a Podman container running the MongoDB database server, we can use the following command:

				
					$ podman run --name mongodb-server -v /opt/mongodb-data:/data/db -d mongo:latest
				
			

Conclusion

In this article, we have discussed the Manage Containers section of the RHCSA 9 exam. We have covered various topics such as finding and retrieving container images from a remote registry, inspecting container images, performing container management using commands such as podman and skopeo, building a container from a Containerfile, performing basic container management such as running, starting, stopping, and listing running containers, running a service inside a container, configuring a container to start automatically as a systemd service, and attaching persistent storage to a container.

By following the examples provided in this article, Linux professionals can gain the necessary knowledge and skills to manage containers effectively and pass the Manage Containers section of the RHCSA 9 exam.

Was this article helpful to you? If so, leave us a comment below. We appreciate you feedback!

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *