Dit deel is nog niet vertaald. Je ziet de Engelse tekst.
Doel
As the normal user student, run a web server in a container, keep its content on the host, build your own image, and make the container start at boot as a user service — without any root rights for the container.
Voordat je begint
- server1 with RHEL 10 and internet access to
registry.access.redhat.com. - The user
student(withsudoonly for package install, firewall and linger). sudo dnf install -y container-tools.
Taken
Vink een taak aan als hij klaar is. Alleen je browser onthoudt dit.
- As
student, pullregistry.access.redhat.com/ubi10/httpd-24and find out which ports it exposes. - Make the folder
~/sitewith anindex.htmlthat saysrootless works. Run a container namedsitefrom the image, publish host port8080to the container's web port, and mount~/siteas the document root/var/www/html. - Show the logs of the container, and run
cat /etc/os-releaseinside it. - Write a Containerfile in
~/buildthat starts from the same image and copies a fileindex.html(textbuilt image) into/var/www/html/. Build it aslocalhost/built:1.0and run it once on port8081to test it, then remove that test container. - Remove the container
site. Make a Quadlet file so thatsite(same image, port and folder as in task 2) runs as a user service calledsite.service, restarts when it stops, and starts at boot. - Make sure the service of
studentstarts at boot without a login, open port8080/tcpin the firewall, and reboot. Check from server2 or your laptop.
Controleer je werk
podman image inspect registry.access.redhat.com/ubi10/httpd-24 --format '{{.Config.ExposedPorts}}'
systemctl --user is-active site.service
podman ps --format '{{.Names}} {{.Ports}}'
curl -s http://localhost:8080/
loginctl show-user student -p Linger
podman images localhost/builtsystemctl --user is-active site.serviceprintsactiveafter a reboot, before you log in to a desktop.curlprintsrootless works.Linger=yes.
Hints
Toon de hints
- Rootless containers can not publish host ports below 1024; that is why the task uses 8080.
:Zat the end of-v(orVolume=) gives the folder the SELinux label for the container.- Quadlet files for users go in
~/.config/containers/systemd/NAME.container. Thensystemctl --user daemon-reload. - Generated Quadlet units can not be enabled.
WantedBy=default.targetin[Install]makes them start at boot.
Oplossing
Toon de oplossing
- Pull and inspect.
- Content and container.
- Logs and a command inside.
- Build your own image.
mkdir -p ~/build && cd ~/build echo "built image" > index.html printf 'FROM registry.access.redhat.com/ubi10/httpd-24\nCOPY index.html /var/www/html/index.html\n' > Containerfile podman build -t localhost/built:1.0 . podman run -d --name test -p 8081:8080 localhost/built:1.0 curl -s http://localhost:8081/ podman rm -f test - The Quadlet file.
podman rm -f site mkdir -p ~/.config/containers/systemd vim ~/.config/containers/systemd/site.container cat ~/.config/containers/systemd/site.container [Unit] Description=Rootless site [Container] Image=registry.access.redhat.com/ubi10/httpd-24 ContainerName=site PublishPort=8080:8080 Volume=%h/site:/var/www/html:Z [Service] Restart=always [Install] WantedBy=default.target systemctl --user daemon-reload systemctl --user start site.service systemctl --user status site.service - Linger, firewall, reboot.
sudo loginctl enable-linger student sudo firewall-cmd --add-port=8080/tcp --permanent sudo firewall-cmd --reload sudo systemctl reboot
Mijn notities
Nog geen notities.