Chapter 21: Containers with Podman
Exercise: Containers review
Build a small web image, run it as a systemd service of the user student with Quadlet, and make it survive a reboot and serve another machine. Everything runs rootless, except the two commands that change the system (lingering and the firewall).
Containers review
- Build a tagged image from a Containerfile.
- Run it as a Quadlet user service.
- Enable lingering and open the port for another host.
Before you start: reset the servers and complete this chapter's lessons. You work on servera as student, connected with ssh student@servera; lab start and lab grade run on workstation. The lab needs access to registry.access.redhat.com.
On servera, as student:
- Install
podmanif needed. Create~/portal/index.htmlwithPortal is upand aContainerfilethat builds onregistry.access.redhat.com/ubi9/httpd-24and copies the page. - Build it as
localhost/portal:1. - Write
~/.config/containers/systemd/portal.container: that image,PublishPort=8080:8080,Restart=always, wanted bydefault.target. - Start
portal.service; the containersystemd-portalmust run. - Enable lingering for student, open
8080/tcppermanently, and test from serverb. - On workstation, fill in
answers.txt.
Start the exercise
[student@workstation ~]$ lab start sa-containers-review
[student@workstation ~]$ ssh student@servera
[student@servera ~]$The image
[student@servera ~]$ sudo dnf install -y podman > /dev/null
[student@servera ~]$ mkdir -p ~/portal && cd ~/portal
[student@servera portal]$ echo "Portal is up" > index.html
[student@servera portal]$ cat > Containerfile <<'EOT'
FROM registry.access.redhat.com/ubi9/httpd-24:latest
COPY index.html /var/www/html/index.html
EOT
[student@servera portal]$ podman build -t localhost/portal:1 . | tail -2
Successfully tagged localhost/portal:1
8783f7652eb1f58df91e9c935a51986cbb9e3de30809eb517a08e5e4f883b136The service
[student@servera portal]$ mkdir -p ~/.config/containers/systemd
[student@servera portal]$ cat > ~/.config/containers/systemd/portal.container <<'EOT'
[Unit]
Description=Portal container
[Container]
Image=localhost/portal:1
PublishPort=8080:8080
[Service]
Restart=always
[Install]
WantedBy=default.target
EOT
[student@servera portal]$ systemctl --user daemon-reload
[student@servera portal]$ systemctl --user start portal.service
[student@servera portal]$ sleep 3; systemctl --user is-active portal.service; curl -s localhost:8080
active
Portal is upBoot and network
[student@servera portal]$ sudo loginctl enable-linger student
[student@servera portal]$ sudo firewall-cmd --permanent --add-port=8080/tcp; sudo firewall-cmd --reload
success
success
[student@serverb ~]$ curl -s -m 3 http://servera:8080/
Portal is upA reboot of servera is the final proof: the portal answers again after a minute, with nobody logged in.
Grade
On workstation, fill in answers.txt and grade:
Check your work with lab grade sa-containers-review, then put the exercise away with lab finish sa-containers-review.