In this lab, you will configure a container on your server that provides a MariaDB database service, stores its database on persistent storage, and starts automatically with the server.
Outcomes
You should be able to:
Create detached containers.
Configure port redirection and persistent storage.
Configure systemd for 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 containers-review start command.
This command runs a start script that determines if the serverb machine is reachable on the network.
It also installs the MariaDB client and creates the podsvc user account that you use to run a MariaDB container.
[student@workstation ~]$lab containers-review start
Procedure 13.6. Instructions
On serverb, install the container tools.
Log in to serverb as the student user, and then use the sudo command.
The password for the student user is student.
Use the ssh command to log in to serverb as the student user.
The systems are configured to use SSH keys for authentication, so a password is not required.
[student@workstation ~]$ssh student@serverb...output omitted...[student@serverb ~]$
Install the container-tools Yum module using the yum command.
[student@serverb ~]$sudo yum module install container-tools[sudo] password for student:student...output omitted...Is this ok [y/N]:y...output omitted... Complete!
The container image registry at registry.lab.example.com stores the rhel8/mariadb-103 image with several tags.
On serverb, as the podsvc user, list those tags and take note of the tag with the lowest version number.
You will use that image tag to start a container later in this exercise.
The password for the podsvc user is redhat.
To query the registry.lab.example.com registry, use the admin account with redhat321 for the password.
Exit from the student account on serverb.
[student@serverb ~]$exitlogout Connection to serverb closed.[student@workstation ~]$
Use the ssh command to log in to serverb as the podsvc user.
The systems are configured to use SSH keys for authentication, so a password is not required.
[student@workstation ~]$ssh podsvc@serverb...output omitted...[podsvc@serverb ~]$
Log in to the container registry using the podman login command.
[podsvc@serverb ~]$podman login registry.lab.example.comUsername:adminPassword:redhat321Login Succeeded!
Use the skopeo inspect command to view information about the registry.lab.example.com/rhel8/mariadb-103 image.
The following skopeo inspect command is very long and should be entered as a single line.
[podsvc@serverb ~]$skopeo inspect docker://registry.lab.example.com/rhel8/mariadb-103{ "Name": "registry.lab.example.com/rhel8/mariadb-103", "Digest": "sha256:a95b...4816", "RepoTags": [ "1-86", "1-102", "latest" ], ...output omitted...
The tag with the lowest number is 1-86.
On serverb, as the podsvc user, create the /home/podsvc/db_data directory.
Prepare the directory so that containers have read/write access.
You will use this directory for persistent storage.
On serverb, as the podsvc user, create a detached MariaDB container named inventorydb.
Use the rhel8/mariadb-103 image from the registry.lab.example.com registry, specifying the tag with the lowest version number on that image, which you found in a preceding step.
Map port 3306 in the container to port 13306 on the host.
Mount the /home/podsvc/db_data directory on the host as /var/lib/mysql/data in the container.
Declare the following variable values:
| Variable | Value |
|---|---|
MYSQL_USER
|
operator1
|
MYSQL_PASSWORD
|
redhat
|
MYSQL_DATABASE
|
inventory
|
MYSQL_ROOT_PASSWORD
|
redhat
|
You can copy and paste these parameters from the /home/podsvc/containers-review/variables file on serverb.
To confirm that the MariaDB database is running, use the mysql command.
You can find this command in the /home/podsvc/containers-review/testdb.sh script.
You can also directly run the script to test the database.
Use the podman run command to create the container.
The following podman run command is very long and should be entered as a single line.
[podsvc@serverb ~]$podman run -d --name inventorydb -p 13306:3306 -v /home/podsvc/db_data:/var/lib/mysql/data:Z -e MYSQL_USER=operator1 -e MYSQL_PASSWORD=redhat -e MYSQL_DATABASE=inventory -e MYSQL_ROOT_PASSWORD=redhat registry.lab.example.com/rhel8/mariadb-103:1-86...output omitted...
Confirm that the database is running.
[podsvc@serverb ~]$~/containers-review/testdb.shTesting the access to the database...SUCCESS
On serverb, as the podsvc user, configure systemd so that the inventorydb container starts automatically with the server.
If you used sudo or su to log in as the podsvc user, then exit serverb and use the ssh command to directly log in to serverb as the podsvc user.
Remember, systemd requires that the user open a direct session from the console or through SSH.
[student@workstation ~]$ssh podsvc@serverb...output omitted...[podsvc@serverb ~]$
Create the ~/.config/systemd/user/ directory.
[podsvc@serverb ~]$mkdir -p ~/.config/systemd/user/[podsvc@serverb ~]$
Use the podman generate systemd command to create the systemd unit file from the running container.
[podsvc@serverb ~]$cd ~/.config/systemd/user/[podsvc@serverb user]$podman generate systemd --name inventorydb --files --new/home/podsvc/.config/systemd/user/container-inventorydb.service
Stop and then delete the inventorydb container.
[podsvc@serverb user]$podman stop inventorydb0d28f0e0a4118ff019691e34afe09b4d28ee526079b58d19f03b324bd04fd545[podsvc@serverb user]$podman rm inventorydb0d28f0e0a4118ff019691e34afe09b4d28ee526079b58d19f03b324bd04fd545
Instruct systemd to reload its configuration, and then enable and start the container-inventorydb service.
[podsvc@serverb user]$systemctl --user daemon-reload[podsvc@serverb user]$systemctl --user enable --now container-inventorydb.serviceCreated symlink /home/podsvc/.config/systemd/user/multi-user.target.wants/container-inventorydb.service → /home/podsvc/.config/systemd/user/container-inventorydb.service. Created symlink /home/podsvc/.config/systemd/user/default.target.wants/container-inventorydb.service → /home/podsvc/.config/systemd/user/container-inventorydb.service.
Confirm that the container is running.
[podsvc@serverb user]$~/containers-review/testdb.shTesting the access to the database... SUCCESS[podsvc@serverb user]$podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 3ab24e7f000d registry.lab.example.com/rhel8/mariadb-103:1-86 run-mysqld 47 seconds ago Up 46 seconds ago 0.0.0.0:13306->3306/tcp inventorydb
Run the loginctl enable-linger command for the user services to start automatically when the server starts.
[podsvc@serverb ~]$loginctl enable-linger[podsvc@serverb ~]$
Exit from serverb.
[podsvc@serverb ~]$exitlogout Connection to serverb closed.[student@workstation ~]$
This concludes the lab.