RHCSA Rapid Track
Course update
An updated version of this course is available that uses a newer version of Red Hat Enterprise Linux in the lab environment. Therefore, the RHEL 9.0 version of the lab environment will retire on December 31, 2024. Please complete any work in this lab environment before it is removed on December 31, 2024. For the most up-to-date version of this course, we recommend moving to the RHEL 9.3 version.
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.
Outcomes
Create rootless detached containers.
Configure port mapping and persistent storage.
Configure
systemdfor a container to manage it withsystemctlcommands.
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. 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.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
productionDNS-enabled container network. Use the10.81.0.0/16subnet and10.81.0.1as the gateway. Use this container network for the containers that you create in this comprehensive review.Create the
db-app01detached container based on theregistry.lab.example.com/rhel8/mariadb-103container image with the lowest tag number in theproductionnetwork. 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 in theproductionnetwork. The container image name must behttp-clientwith the9.0tag. 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/* .[podmgr@serverb ~]$ls -ltotal 0 drwxr-xr-x. 2 podmgr podmgr 27 May 10 21:52 db-dev drwxr-xr-x. 2 podmgr podmgr 44 May 10 21:52 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 May 10 21:55 database
Create the
productionDNS-enabled container network. Use the10.81.0.0/16subnet and10.81.0.1as the gateway. Use this container network for the containers that you create in this comprehensive review.Create the
productionDNS-enabled container network. Use the10.81.0.0/16subnet and10.81.0.1as the gateway.[podmgr@serverb ~]$
podman network create --gateway 10.81.0.1 \--subnet 10.81.0.0/16 productionproductionVerify that the DNS feature is enabled in the
productionnetwork.[podmgr@serverb ~]$
podman network inspect production[ { "name": "production", ...output omitted... "subnets": [ { "subnet": "10.81.0.0/16", "gateway": "10.81.0.1" } ], ...output omitted... "dns_enabled": true, ...output omitted...
Create the
db-app01detached container based on theregistry.lab.example.com/rhel8/mariadb-103container image with the lowest tag number in theproductionnetwork. 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_PASSWORDredhatSearch for the earliest version tag number of the
registry.lab.example.com/rhel8/mariadbcontainer image.[podmgr@serverb ~]$
skopeo inspect \docker://registry.lab.example.com/rhel8/mariadb-103{ "Name": "registry.lab.example.com/rhel8/mariadb-103", "Digest": "sha256:a95b678e52bb9f4305cb696e45c91a38c19a7c2c5c360ba6c681b10717394816", "RepoTags": ["1-86", "1-102", "latest" ...output omitted...Use the earliest version tag number from the output of the previous step to create the detached
db-app01container in theproductionnetwork. 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 \--network production -p 13306:3306 \-v /home/podmgr/storage/database:/var/lib/mysql/data:Z \registry.lab.example.com/rhel8/mariadb-103:1-86...output omitted... ba398d080e00ba1d52b1cf4f5959c477681cce343c11cc7fc39e4ce5f1cf2384 [podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba398d080e00 registry.lab.example.com/rhel8/mariadb-103:1-86 run-mysqld 20 seconds ago Up 20 seconds ago 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 ba398d080e00 registry.lab.example.com/rhel8/mariadb-103:1-86 run-mysqld About an hour ago Exited (0) 3 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; disabled; vendor preset: disabled) Active: active (running) since Tue 2022-05-10 22:16:23 EDT; 7s ago ...output omitted... [podmgr@serverb ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ba398d080e00 registry.lab.example.com/rhel8/mariadb-103:1-86 run-mysqld 59 seconds ago Up About a minute ago 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 in theproductionnetwork. The container image name must behttp-clientwith the9.0tag. 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/rhel8/php-74:1-63 ...output omitted...Create the
http-app01detached container in theproductionnetwork. Map the 8080 port from the local machine to the 8080 port in the container.[podmgr@serverb ~]$
podman run -d --name http-app01 \ --network production -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/rhel8/mariadb-103: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 ~]$
This concludes the section.