Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Use Podman to Create Persistent systemd Containers and Pods on RHEL

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.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Apr 23, 2021

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    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.
  2. Challenge

    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.
  3. Challenge

    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.
  4. Challenge

    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
  5. Challenge

    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!

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

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.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans