Skill 11
Skill 11
Skill 11
Guided Exercise
Outcomes
• Create systemd service files to manage a container.
• Configure a container so you can manage it with systemctl commands.
• Configure a user account for systemd user services to start a container when the host
machine starts.
This command prepares your environment and ensures that all required resources are
available.
Instructions
1. Log in to the servera machine as the student user.
2. Create a user account called contsvc and use redhat as the password. Use this user
account to run containers as systemd services.
2.1. Create the contsvc user. Set redhat as the password for the contsvc user.
2.2. To manage the systemd user services with the contsvc account, you must log in
directly as the contsvc user. You cannot use the su and sudo commands to create a
session with the contsvc user.
RH134-RHEL9.0-en-2-20220609 367
Chapter 11 | Run Containers
Return to the workstation machine as the student user, and then log in as the
contsvc user.
3.2. The lab script prepares the registries.conf file in the /tmp/containers-
services/ directory. Copy that file to the ~/.config/containers/ directory.
3.3. Verify that you can access the registry.lab.example.com registry. If everything
works as expected, then the command should list some images.
4.2. Create the index.html file and add the Hello World line.
4.3. Confirm that the permission for others is set to r-- in the index.html file. The
container uses a non-privileged user that must be able to read the index.html file.
368 RH134-RHEL9.0-en-2-20220609
Chapter 11 | Run Containers
6. Create a systemd service file to manage the webapp container with systemctl
commands. Configure the systemd service so that when you start the service, the
systemd daemon creates a container. After you finish the configuration, stop and then
delete the webapp container. Remember that the systemd daemon expects that the
container does not exist initially.
6.2. Create the unit file for the webapp container. Use the --new option so that systemd
creates a container when starting the service and deletes the container when
stopping the service.
RH134-RHEL9.0-en-2-20220609 369
Chapter 11 | Run Containers
7. Reload the systemd daemon configuration, and then enable and start your new
container-webapp user service. Verify the systemd service configuration, stop and
start the service, and display the web server response and the container status.
Notice the container ID. Use this information to confirm that systemd creates a
container when you restart the service.
7.5. Stop the container-webapp service, and confirm that the container no longer
exists. When you stop the service, systemd stops and then deletes the container.
7.6. Start the container-webapp service, and then confirm that the container is
running.
370 RH134-RHEL9.0-en-2-20220609
Chapter 11 | Run Containers
The container ID is different, because the systemd daemon creates a container with
the start instruction and deletes the container with the stop instruction.
8. Ensure that the services for the contsvc user start at system boot. When done, restart the
servera machine.
8.2. Confirm that the Linger option is set for the contsvc user.
8.3. Switch to the root user, and then use the systemctl reboot command to restart
servera.
[contsvc@servera user]$ su -
Password: redhat
Last login: Fri Aug 28 07:43:40 EDT 2020 on pts/0
[root@servera ~]# systemctl reboot
Connection to servera closed by remote host.
Connection to servera closed.
[student@workstation ~]$
9. When the servera machine is up again, log in to servera as the contsvc user. Verify
that systemd started the webapp container and that the web content is available.
RH134-RHEL9.0-en-2-20220609 371
Chapter 11 | Run Containers
Finish
On the workstation machine, run the lab finish containers-services script to
complete this exercise.
372 RH134-RHEL9.0-en-2-20220609