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
podmancontainer based on thenginx:latestimage. - Generate a
systemduser service file for the container. - Enable the service to start automatically for the
labexuser. - Enable lingering for the
labexuser 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
podmanfor 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
8080to the container's port80. - The
systemdservice file must be generated usingpodman generate systemd. - The generated service file must be placed at
~/.config/systemd/user/container-my-nginx.service. - Lingering must be enabled for the
labexuser usingloginctl.
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.



