Use Podman to Create Persistent systemd Containers and Pods on RHEL

1 hour
  • 5 Learning Objectives

About this Hands-on Lab

Podman has the ability to generate systemd unit files, making quick work of configuring systemd containers. In this lab, we will examine how to use Podman to generate systemd unit files from existing Podman containers and configure these containers for persistence. Upon completion of this lab, you will be able to configure your Podman containers and pods as persistent systemd containers and pods.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Start Our WordPress Pod

We’re going to stand up a WordPress instance in a pod.

Perform the following tasks as cloud_user:

  • Check for existing rootless containers and pods.
  • Start by creating our pod. Remember, we want to publish port "80" in the pod to "8080" on the host. We want to name the pod "wp-pod".
  • Check again for pods and containers. You should see your Infra container.
  • Start the mariadb container.
    • Name the container "wp-db".
    • Add the container to the wp-pod pod.
    • Set --restart=always.
    • Use the "mariadb" short name for the container image.
    • Set the following variables
    • MYSQL_ROOT_PASSWORD="dbpass"
    • MYSQL_DATABASE="wp"
    • MYSQL_USER="wordpress"
    • MYSQL_PASSWORD="wppass"
  • Check for containers again.
  • Next, we’ll start the WordPress container
    • Name the container "wp-web".
    • Add the container to the wp-pod pod.
    • Set --restart=always.
    • Use the "wordpress" short name for the container image
    • Set the following variables
    • WORDPRESS_DB_NAME="wp"
    • WORDPRESS_DB_USER="wordpress"
    • WORDPRESS_DB_PASSWORD="wppass"
    • WORDPRESS_DB_HOST="127.0.0.1"
  • Check for containers and pods again.
  • Check connectivity with a curl command on localhost:8080. You won’t get anything back. Check the exit code immediately. It should be 0. If you’d like to try connecting with a web browser on the lab server’s public IP, on port 8080, you can.Let’s generate systemd unit files for our wp-pod pod!

Perform the following:

  • Create the ~/.config/systemd/user directory.
  • Change directory to the new directory.
  • Generate our systemd unit files from our running pod.
  • Take a look at our unit files.
  • Stop and remove all pods.
  • Check again for containers and pods.
Generate Our systemd Unit Files

Let’s generate systemd unit files for our wp-pod pod!

Perform the following:

  • Create the ~/.config/systemd/user directory.
  • Change directory to the new directory.
  • Generate our systemd unit files from our running pod.
  • Take a look at our unit files.
  • Stop and remove all pods.
  • Check again for containers and pods.
Enable and Start Our WordPress Pod Using systemd

We’re going to enable and start our wp-pod pod using systemd.

Perform the following:

  • Reload systemd as a non-root user (cloud_user) to pick up the new unit.
  • Enable and start the container service as a non-root user.
  • Check the status of our new systemd WordPress pod.
  • Check for containers and pods again.
  • Check connectivity with a curl command on localhost:8080. You won’t get anything back. Check the exit code immediately. It should be 0. If you’d like to try connecting with a web browser on the lab server’s public IP, on port 8080, you can.
Make Our WordPress Pod Persistent

We’re going to configure our container to start when the system boots.

Perform the following:

  • Check to see if linger is enabled for cloud_user
  • Enable linger for cloud_user.
  • Check to see if linger is enabled for cloud_user again
Test Persistence

Let’s test our persistent setup for our wp-pod pod!

Perform the following:

  • Reboot to test our pod for persistence.
  • Check for containers and pods again.
  • Check connectivity with a curl command on localhost:8080. You won’t get anything back. Check the exit code immediately. It should be 0. If you’d like to try connecting with a web browser on the lab server’s public IP, on port 8080, you can.

Congratulations, Cloud Guru! You just created a persistent systemd pod!

Additional Resources

Our developers need some WordPress pods!

Each development team member has received a new development laptop running RHEL. They would like us to help them set up each team member with a WordPress container service that they can use for web development.

Let's do it, using Podman and systemd!

When the lab starts, you will want to open an SSH connection to your lab instance(s):

ssh cloud_user@PUBLIC_IP_ADDRESS

Replace PUBLIC_IP_ADDRESS with either the public IP or DNS of the instance(s). The 'cloud_user' password has been provided with the instance information.

Good luck and enjoy!

What are Hands-on Labs

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.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!