Red Hat System Administration II
Note
If you plan to take the RHCSA exam, then use the following approach to maximize the benefit of this Comprehensive Review: attempt each lab without viewing the solution buttons or referring to the course content. Use the grading scripts to gauge your progress as you complete each lab.
Create rootless detached containers.
Outcomes
Create rootless detached containers.
Configure port mapping and persistent storage.
Configure a container as a
systemdservice and usesystemctlcommands to manage it.
If you did not reset your workstation and server machines at the end of the last chapter, then save any work that you want to keep from earlier exercises on those machines, and reset them now.
As the student user on the workstation machine, use the lab command to prepare your system for this exercise.
This command prepares your environment and ensures that all required resources are available.
[student@workstation ~]$ lab start rhcsa-compreview4
Specifications
On
serverb, configure thepodmgruser withredhatas the password, and set up the appropriate tools for thepodmgruser to manage the containers for this comprehensive review. Configureregistry.lab.example.comas a remote registry. Useadminas the user andredhat321as the password to authenticate to the registry. You can use the/tmp/review4/registries.conffile to configure the registry.The
/tmp/review4/container-devdirectory contains two directories with development files for the containers in this comprehensive review. Copy the two directories under the/tmp/review4/container-devdirectory to thepodmgrhome directory. Configure the/home/podmgr/storage/databasesubdirectory so that you can use it as persistent storage for a container.Create the
db-app01detached container based on theregistry.lab.example.com/rhel9/mariadb-105container image. Use the/home/podmgr/storage/databasedirectory as persistent storage for the/var/lib/mysql/datadirectory of thedb-app01container. Map the 13306 port on the local machine to the 3306 port in the container. Use the values of the following table to set the environment variables to create the containerized database:Variable Value MYSQL_USERdeveloperMYSQL_PASSWORDredhatMYSQL_DATABASEinventoryMYSQL_ROOT_PASSWORDredhatCreate a
systemdservice file to manage thedb-app01container. Configure thesystemdservice so that when you start the service, thesystemddaemon keeps the original container. Start and enable the container as asystemdservice. Configure thedb-app01container to start at system boot.Copy the
/home/podmgr/db-dev/inventory.sqlscript into the/tmpdirectory of thedb-app01container, and execute the script inside the container. If you executed the script locally, then you would use themysql -u root inventory < /tmp/inventory.sqlcommand.Use the container file in the
/home/podmgr/http-devdirectory to create thehttp-app01detached container. The container image name must behttp-client. Map the 8080 port on the local machine to the 8080 port in the container.Use the
curlcommand to query the content of thehttp-app01container. Verify that the output of the command shows the container name of the client and that the status of the database is up.
On
serverb, configure thepodmgruser withredhatas the password and set up the appropriate tools for thepodmgruser to manage the containers for this comprehensive review. Configure theregistry.lab.example.comas the remote registry. Useadminas the user andredhat321as the password to authenticate. You can use the/tmp/review4/registries.conffile to configure the registry.Log in to
serverbas thestudentuser.[student@workstation ~]$
ssh student@serverb...output omitted... [student@serverb ~]$Install the
container-toolsmeta-package.[student@serverb ~]$
sudo dnf install container-tools[sudo] password for student:student...output omitted... Is this ok [y/N]:y...output omitted... Complete!Create the
podmgruser and setredhatas the password for the user.[student@serverb ~]$
sudo useradd podmgr[student@serverb ~]$sudo passwd podmgrChanging password for user podmgr. New password:redhatBAD PASSWORD: The password is shorter than 8 characters Retype new password:redhatpasswd: all authentication tokens updated successfully.Exit the
studentuser session. Log in to theserverbmachine as thepodmgruser. If prompted, useredhatas the password.[student@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation ~]$ssh podmgr@serverb...output omitted... [podmgr@serverb ~]$Create the
~/.config/containersdirectory.[podmgr@serverb ~]$
mkdir -p ~/.config/containersCopy the
/tmp/review4/registries.conffile to the container configuration directory in the home directory.[podmgr@serverb ~]$
cp /tmp/review4/registries.conf ~/.config/containers/Log in to the registry to verify the configuration.
[podmgr@serverb ~]$
podman login registry.lab.example.comUsername:adminPassword:redhat321Login Succeeded!
The
/tmp/review4/container-devdirectory contains two directories with development files for the containers in this comprehensive review. Copy the two directories in the/tmp/review4/container-devdirectory to thepodmgrhome directory. Configure the/home/podmgr/storage/databasesubdirectory so that you can use it as persistent storage for a container.Copy the content of the
/tmp/review4/container-devdirectory to thepodmgrhome directory.[podmgr@serverb ~]$
cp -r /tmp/review4/container-dev/*-dev .[podmgr@serverb ~]$ls -ltotal 0 drwxr-xr-x. 2 podmgr podmgr 27 Jun 18 12:00 db-dev drwxr-xr-x. 3 podmgr podmgr 42 Jun 18 12:00 http-devCreate the
/home/podmgr/storage/databasedirectory in thepodmgrhome directory. Set the appropriate permissions on the directory for the container to mount it as persistent storage.[podmgr@serverb ~]$
mkdir -p storage/database[podmgr@serverb ~]$chmod 0777 storage/database[podmgr@serverb ~]$ls -l storage/total 0 drwxrwxrwx. 2 podmgr podmgr 6 Jun 18 12:05 database
Create the
db-app01detached container based on theregistry.lab.example.com/rhel9/mariadb-105container image. Use the/home/podmgr/storage/databasedirectory as persistent storage for the/var/lib/mysql/datadirectory of thedb-app01container. Map the 13306 port on the local machine to the 3306 port in the container. Use the values of the following table to set the environment variables to create the containerized database:Variable Value MYSQL_USERdeveloperMYSQL_PASSWORDredhatMYSQL_DATABASEinventoryMYSQL_ROOT_PASSWORDredhatInspect the
registry.lab.example.com/rhel9/mariadbcontainer image.[podmgr@serverb ~]$
skopeo inspect \docker://registry.lab.example.com/rhel9/mariadb-105{ "Name": "registry.lab.example.com/rhel9/mariadb-105", "Digest": "sha256:2bf8...fab8", "RepoTags": [ "latest" ], ...output omitted...Use the
registry.lab.example.com/rhel9/mariadb-105container image to create the detacheddb-app01container. Use the/home/podmgr/storage/databasedirectory as persistent storage for the container. Map the 13306 port to the 3306 container port. Use the data in the table to set the environment variables for the container.[podmgr@serverb ~]$
podman run -d --name db-app01 \-e MYSQL_USER=developer \-e MYSQL_PASSWORD=redhat \-e MYSQL_DATABASE=inventory \-e MYSQL_ROOT_PASSWORD=redhat \-p 13306:3306 \-v /home/podmgr/storage/database:/var/lib/mysql/data:Z \registry.lab.example.com/rhel9/mariadb-105...output omitted... 0959ba5df57dec2a478504df633a8cdb54aaad5c98a160de34d1d1b65f8435a6 [podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0959ba5df57d registry.lab.example.com/rhel9/mariadb-105:latest run-mysqld 16 seconds ago Up 15 seconds 0.0.0.0:13306->3306/tcp db-app01
Create a
systemdservice file to manage thedb-app01container. Configure thesystemdservice so that when you start the service, thesystemddaemon keeps the original container. Start and enable the container as asystemdservice. Configure thedb-app01container to start at system boot.Create the
~/.config/systemd/user/directory for the container unit file.[podmgr@serverb ~]$
mkdir -p ~/.config/systemd/user/Create the
systemdunit file for thedb-app01container, and move the unit file to the~/.config/systemd/user/directory.[podmgr@serverb ~]$
podman generate systemd --name db-app01 --files/home/podmgr/container-db-app01.service [podmgr@serverb ~]$mv container-db-app01.service ~/.config/systemd/user/Stop the
db-app01container.[podmgr@serverb ~]$
podman stop db-app01db-app01 [podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0959ba5df57d registry.lab.example.com/rhel9/mariadb-105:latest run-mysqld 2 minutes ago Exited (0) 2 seconds ago 0.0.0.0:13306->3306/tcp db-app01Reload the user
systemdservice to use the new service unit.[podmgr@serverb ~]$
systemctl --user daemon-reloadStart and enable the
systemdunit for thedb-app01container.[podmgr@serverb ~]$
systemctl --user enable --now container-db-app01Created symlink /home/podmgr/.config/systemd/user/default.target.wants/container-db-app01.service → /home/podmgr/.config/systemd/user/container-db-app01.service. [podmgr@serverb ~]$systemctl --user status container-db-app01● container-db-app01.service - Podman container-db-app01.service Loaded: loaded (/home/podmgr/.config/systemd/user/container-db-app01.service; enabled; preset: disabled) Active: active (running) since Fri 2024-06-18 12:18:45 EDT; 13s ago ...output omitted... [podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 0959ba5df57d registry.lab.example.com/rhel9/mariadb-105:latest run-mysqld 2 minutes ago Up 2 minutes 0.0.0.0:13306->3306/tcp db-app01Use the
loginctlcommand to configure thedb-app01container to start at system boot.[podmgr@serverb ~]$
loginctl enable-linger
Copy the
/home/podmgr/db-dev/inventory.sqlscript into the/tmpdirectory of thedb-app01container, and execute the script inside the container. If you executed the script locally, then you would use themysql -u root inventory < /tmp/inventory.sqlcommand.Copy the
/home/podmgr/db-dev/inventory.sqlscript into the/tmpdirectory of thedb-app01container.[podmgr@serverb ~]$
podman cp /home/podmgr/db-dev/inventory.sql \db-app01:/tmp/inventory.sqlExecute the
inventory.sqlscript in thedb-app01container.[podmgr@serverb ~]$
podman exec -it db-app01 sh -c 'mysql -u root \inventory < /tmp/inventory.sql'
Use the container file in the
/home/podmgr/http-devdirectory to create thehttp-app01detached container. The container image name must behttp-client. Map the 8080 port on the local machine to the 8080 port in the container.Create the
http-client:9.0image with the container file in the/home/podmgr/http-devdirectory.[podmgr@serverb ~]$
podman build -t http-client:9.0 http-dev/STEP 1/7: FROM registry.lab.example.com/rhel9/php-82:1-15 ...output omitted...Create the
http-app01detached container. Map the 8080 port from the local machine to the 8080 port in the container.[podmgr@serverb ~]$
podman run -d --name http-app01 \ -p 8080:8080 localhost/http-client:9.0[podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba398d080e00 registry.lab.example.com/rhel9/mariadb-105:1-86 run-mysqld 20 minutes ago Up 20 seconds ago 0.0.0.0:13306->3306/tcp db-app01 ee424df19621 localhost/http-client:9.0 /bin/sh -c 4 seconds ago Up 4 seconds ago 0.0.0.0:8080->8080/tcp http-app01
Query the content of the
http-app01container. Verify that it shows the container name of the client and that the status of the database is up.Verify that the
http-app01container responds to http requests.[podmgr@serverb ~]$
curl 127.0.0.1:8080This is the server http-app01 and the database is up
Return to the
workstationmachine as thestudentuser.[podmgr@serverb ~]$
exitlogout Connection to serverb closed. [student@workstation ~]$