RHCSA Rapid Track
In this review, you will configure a container on your server that provides web content from persistent storage and starts automatically with the server.
Outcomes
You should be able to:
Create rootless detached containers.
Configure port redirection and persistent storage.
Configure
systemdfor containers to start when the host machine starts.
On the workstation machine, log in as the student user with student as the password.
On the workstation machine, run the lab rhcsa-compreview4 start command.
This command runs a start script that determines if the serverb machine is reachable on the network.
It also creates an archive file with some web content and the containers user account that you use to run an Apache HTTP Server container.
[student@workstation ~]$lab rhcsa-compreview4 start
Instructions
Perform the following tasks on serverb as the containers user to complete the comprehensive review:
On
serverb, create the/srv/web/directory, and then extract the/home/containers/rhcsa-compreview4/web-content.tgzarchive in that directory. Configure the directory so that a rootless container can use it for persistent storage.On
serverb, install the container tools.On
serverb, as thecontainersuser, create a detached Apache HTTP Server container namedweb. Use therhel8/httpd-24image with the tag1-105from theregistry.lab.example.comregistry. Map port 8080 in the container to port 8888 on the host. Mount the/srv/webdirectory on the host as/var/wwwin the container. Declare the environment variableHTTPD_MPMwitheventfor the value.On
serverb, as thecontainersuser, configuresystemdso that thewebcontainer starts automatically with the server.
The password for the containers user is redhat.
To access the container image registry at registry.lab.example.com, use the admin account with redhat321 as the password.
You can copy and paste the web container parameters from the /home/containers/rhcsa-compreview4/variables file on serverb.
On
serverb, create the/srv/web/directory, and then extract the/home/containers/rhcsa-compreview4/web-content.tgzarchive in that directory. Configure the directory so that a rootless container can use it for persistent storage.Use the
sshcommand to log in toserverbas thecontainersuser. The systems are configured to use SSH keys for authentication, so a password is not required.[student@workstation ~]$ssh containers@serverb...output omitted...[containers@serverb ~]$Use the
sudo -icommand to switch to therootuser. The password for thecontainersuser isredhat.[containers@serverb ~]$sudo -i[sudo] password for containers:redhat[root@serverb ~]#Create the
/srv/web/directory.[root@serverb ~]#mkdir /srv/web/[root@serverb ~]#Extract the
/home/containers/rhcsa-compreview4/web-content.tgzarchive in the/srv/web/directory.[root@serverb ~]#cd /srv/web/[root@serverb web]#tar xvf /home/containers/rhcsa-compreview4/web-content.tgzhtml/ html/index.html[root@serverb web]#Rootless containers require read access to the
/srv/web/directory and its contents. Also, thepodmancommand running as thecontainersuser must be able to relabel the directory for SELinux. Set the directory owner tocontainers, and then confirm that everyone has access to the content.[root@serverb web]#chown -R containers: /srv/web[root@serverb web]#ls -ld /srv/web/drwxr-xr-x. 3 containers containers 18 Sep 7 04:43 /srv/web/[root@serverb web]#ls -ld /srv/web/html/drwxr-xr-x. 2 containers containers 24 Sep 7 04:01 /srv/web/html/[root@serverb web]#ls -l /srv/web/html/index.html-rw-r--r--. 1 containers containers 546 Sep 7 04:01 /srv/web/html/index.html
On
serverb, install the container tools.On
serverb, as thecontainersuser, create a detached container namedweb. Use therhel8/httpd-24image with the tag1-105from theregistry.lab.example.comregistry. Map port 8080 in the container to port 8888 on the host. Mount the/srv/webdirectory on the host as/var/wwwin the container. Declare the environment variableHTTPD_MPMwith a value ofevent.You can copy and paste these parameters from the
/home/containers/rhcsa-compreview4/variablesfile onserverb.Log in to the container image registry at
registry.lab.example.comusing theadminaccount withredhat321as the password.[containers@serverb ~]$podman login registry.lab.example.comUsername:adminPassword:redhat321Login Succeeded!Use the
podman runcommand to create the container. The followingpodman runcommand is very long and should be entered as a single line.[containers@serverb ~]$podman run -d --name web -p 8888:8080 -v /srv/web:/var/www:Z -e HTTPD_MPM=event registry.lab.example.com/rhel8/httpd-24:1-105...output omitted...Use the
curlcommand to confirm that the Apache HTTP Server is running.[containers@serverb ~]$curl http://localhost:8888/Comprehensive Review Web Content Test Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet lacus vestibulum, varius magna sit amet, tempus neque. ...output omitted...That content comes from the
web-content.tgzarchive you previously extracted.
On
serverb, as thecontainersuser, configuresystemdso that thewebcontainer starts automatically with the server.If you used
sudoorsuto log in as thecontainersuser, then exitserverband use thesshcommand to directly log in toserverbas thecontainersuser.[student@workstation ~]$ssh containers@serverb...output omitted...[containers@serverb ~]$Create the
~/.config/systemd/user/directory.[containers@serverb ~]$mkdir -p ~/.config/systemd/user/[containers@serverb ~]$Use the
podman generate systemdcommand to create thesystemdunit file from the running container.[containers@serverb ~]$cd ~/.config/systemd/user/[containers@serverb user]$podman generate systemd --name web --files --new/home/containers/.config/systemd/user/container-web.serviceStop and then delete the
webcontainer.[containers@serverb user]$podman stop webd16a826c936efc7686d8d8e5617b727f5d272361c54f8a0ca65c57d012347784[containers@serverb user]$podman rm webd16a826c936efc7686d8d8e5617b727f5d272361c54f8a0ca65c57d012347784Instruct
systemdto reload its configuration, and then enable and start thecontainer-webservice.[containers@serverb user]$systemctl --user daemon-reload[containers@serverb user]$systemctl --user enable --now container-web.serviceCreated symlink /home/containers/.config/systemd/user/multi-user.target.wants/container-web.service → /home/containers/.config/systemd/user/container-web.service. Created symlink /home/containers/.config/systemd/user/default.target.wants/container-web.service → /home/containers/.config/systemd/user/container-web.service.Confirm that the container is running.
[containers@serverb user]$curl http://localhost:8888/Comprehensive Review Web Content Test Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed sit amet lacus vestibulum, varius magna sit amet, tempus neque. ...output omitted...Run the
loginctl enable-lingercommand for the user services to start automatically with the server.[containers@serverb ~]$loginctl enable-linger[containers@serverb ~]$Exit from
serverb.[containers@serverb ~]$exitlogout Connection to serverb closed.[student@workstation ~]$
This concludes the comprehensive review.