- Lab
- A Cloud Guru
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.
Path Info
Table of Contents
-
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 onlocalhost:8080
. You won't get anything back. Check the exit code immediately. It should be0
. If you'd like to try connecting with a web browser on the lab server's public IP, on port8080
, you can.Let's generatesystemd
unit files for ourwp-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.
-
Challenge
Generate Our systemd Unit Files
Let's generate
systemd
unit files for ourwp-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.
- Create the
-
Challenge
Enable and Start Our WordPress Pod Using systemd
We're going to enable and start our
wp-pod
pod usingsystemd
.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 onlocalhost:8080
. You won't get anything back. Check the exit code immediately. It should be0
. If you'd like to try connecting with a web browser on the lab server's public IP, on port8080
, you can.
- Reload
-
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 forcloud_user
- Enable
linger
forcloud_user
. - Check to see if
linger
is enabled forcloud_user
again
- Check to see if
-
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 onlocalhost:8080
. You won't get anything back. Check the exit code immediately. It should be0
. If you'd like to try connecting with a web browser on the lab server's public IP, on port8080
, you can.
Congratulations, Cloud Guru! You just created a persistent
systemd
pod!
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.