Configure a Podman Container to Start Automatically as a systemd User Service

Red Hat Enterprise LinuxBeginner
Practice Now

Introduction

In this challenge, you will learn how to configure a Podman container to start automatically as a systemd user service. This is a common and recommended practice in Red Hat Enterprise Linux (RHEL) environments for ensuring that your containerized applications are running and available when the system boots. By completing this challenge, you will gain practical experience in managing container lifecycles with podman and integrating them with the system's systemd init process, a core competency for a System Administrator.

Configure a Container to Start Automatically as a systemd Service

In this challenge, you will configure a container to start automatically as a systemd service. This is useful for ensuring that your containerized applications are always running and accessible.

Tasks

Your goal is to run an Nginx web server in a Podman container and configure it to launch automatically on system startup.

  • Create and run a podman container based on the nginx:latest image.
  • Generate a systemd user service file for the container.
  • Enable the service to start automatically for the labex user.
  • Enable lingering for the labex user to ensure the service starts at boot, even without an active login session.
  • Verify that the container is running and the Nginx service is accessible.

Requirements

  • You must use podman for all container management tasks.
  • The container image must be docker.io/library/nginx:latest.
  • The container must be named my-nginx.
  • The container must map host port 8080 to the container's port 80.
  • The systemd service file must be generated using podman generate systemd.
  • The generated service file must be placed at ~/.config/systemd/user/container-my-nginx.service.
  • Lingering must be enabled for the labex user using loginctl.

Example

After completing this challenge, you should be able to access the Nginx welcome page by running curl http://localhost:8080. The output should look like this:

<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
...
<p><em>Thank you for using nginx.</em></p>
</body>
</html>

Summary

In this challenge, you have learned how to use podman to create a container and then generate a systemd user service to manage its lifecycle. You configured the service to start automatically and enabled lingering to ensure it launches at system boot. This process is fundamental for deploying resilient, containerized applications on RHEL and similar systems, providing a robust alternative to older methods.

✨ Check Solution and Practice