RHCSA Rapid Track
In this exercise, you will use podman to manage containers running on your server.
Outcomes
You should be able to create and manage containers.
On the workstation machine, run the lab containers-advanced start command.
This command runs a start script to determine whether the servera machine is reachable on the network.
Additionally, it installs the MariaDB client on servera, checks and configures the container registry, and ensures that the container images used for this exercise are stored there.
[student@workstation ~]$lab containers-advanced start
Procedure 16.3. Instructions
Use the
sshcommand to log in toserveraas thestudentuser. The systems are configured to use SSH keys for authentication, so a password is not required.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Log in to the container registry using the
podman logincommand.[student@servera ~]$podman login registry.lab.example.comUsername:adminPassword:redhat321Login Succeeded!Create a detached MariaDB database container based on the specification in the following substeps using the
podman runcommand. Confirm that the container is running and publishes the correct ports.Note
If you start a container with
podman run, and you have not already pulled the specified container image fromregistry.lab.example.com, then the command will automatically pull the requested image from the registry.Create a detached container named
mydbthat uses the container imageregistry.lab.example.com/rhel8/mariadb-103:1-102. Your command must publish port 3306 in the container to the same port number on the host. You must also declare the following variable values to configure the container with the database useruser1(passwordredhat), set therootpassword toredhat, and create the databaseitems.Variable Value MYSQL_USERuser1MYSQL_PASSWORDredhatMYSQL_DATABASEitemsMYSQL_ROOT_PASSWORDredhatThe following
podman runcommand is very long and should be entered as a single line. As a convenience, you can copy and paste the following command from the/tmp/containers-advanced/create-mydb.txtfile.[student@servera ~]$podman run -d --name mydb -e MYSQL_USER=user1 -e MYSQL_PASSWORD=redhat -e MYSQL_DATABASE=items -e MYSQL_ROOT_PASSWORD=redhat -p 3306:3306 registry.lab.example.com/rhel8/mariadb-103:1-102Trying to pull registry.lab.example.com/rhel8/mariadb-103:1-102... Getting image source signatures Copying blob 71391dc11a78 done Copying blob 77c58f19bd6e done Copying blob 67b9f0b530d9 done Copying blob 47db82df7f3f done Copying config 11a47e0fbe done Writing manifest to image destination Storing signatures abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815[student@servera ~]$Confirm that the container is running and publishing the correct ports using the
podman pscommand.[student@servera ~]$podman psCONTAINER ID IMAGE COMMAND abcb42ef2ff1 registry.lab.example.com/rhel8/mariadb-103:1-102 run-mysqld CREATED STATUS PORTS NAMES bout a minute ago Up About a minute ago0.0.0.0:3306->3306/tcpmydb
Connect to the MariaDB database in your
mydbcontainer using themysqlcommand. Confirm that theitemsdatabase exist, and then exit from MariaDB and stop themydbcontainer.Connect to MariaDB as
user1withredhatas the password. Specify port 3306 and the IP address oflocalhost, which is your container host (127.0.0.1).[student@servera ~]$mysql -u user1 -p --port=3306 --host=127.0.0.1Enter password:redhatWelcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.3.17-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>Confirm the
itemsdatabase exist, and then exit from MariaDB.MariaDB [(none)]>show databases;+--------------------+ | Database | +--------------------+ | information_schema | |items| | test | +--------------------+ 3 rows in set (0.001 sec)MariaDB [(none)]>exitBye[student@servera ~]$Stop the
mydbcontainer. Your container ID will be different from the following:[student@servera ~]$podman stop mydbabcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815
Create a container running an Apache HTTP Server that also starts an interactive Bash shell in the container. Run a command using the container's shell, and then exit the container and verify that the container is no longer running.
Create a container named
mywebthat is running Apache HTTP Server 2.4, and also starts an interactive shell in the container. Use theregistry.lab.example.com/rhel8/httpd-24:1-105container image. The followingpodman runcommand is very long and should be entered as a single line.[student@servera ~]$podman run --name myweb -it registry.lab.example.com/rhel8/httpd-24:1-105 /bin/bash...output omitted...bash-4.4$At the interactive shell prompt in the container, run the
cat /etc/redhat-releasecommand to display the contents of the/etc/redhat-releasefile in the container. Exit the container.bash-4.4$cat /etc/redhat-releaseRed Hat Enterprise Linux release 8.2 (Ootpa)bash-4.4$exitexit[student@servera ~]$Verify that the
mywebcontainer is no longer running.[student@servera ~]$podman ps -aCONTAINER ID IMAGE COMMAND 6d95bd8559de registry.lab.example.com/rhel8/httpd-24:1-105 /bin/bash abcb42ef2ff1 registry.lab.example.com/rhel8/mariadb-103:1-102 run-mysqld CREATED STATUS PORTS NAMES About a minute agoExited (0) 25 seconds agomyweb9 minutes ago Exited (0) 3 minutes ago 0.0.0.0:3306->3306/tcp mydb
Create a detached HTTPD web server container named
mysecondweb. Connect to the container using its name, and then display the kernel name and release. Connect to the container a second time, but use the (-l) option to recall the ID of the container from the previous command and display the system load average. Leave the container running.Create a detached container named
mysecondweb. Your output will vary from the the example in this exercise.[student@servera ~]$podman run --name mysecondweb -d registry.lab.example.com/rhel8/httpd-24:1-1059e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028Connect to the
mysecondwebcontainer to display the Linux name and kernel release using thepodman execcommand.[student@servera ~]$podman exec mysecondweb uname -srLinux 4.18.0-193.el8.x86_64Run the
podman execcommand again, this time using the (-l) option to use the container ID from the previous command to display the system load average.[student@servera ~]$podman exec -l uptime00:14:53 up 2:15, 0 users, load average: 0.08, 0.02, 0.01Leave the
mysecondwebcontainer running.
Create a container named
myquickwebthat lists the contents of the/etc/redhat-releasefile, and then automatically exits and deletes the container. Confirm that the container is deleted.Create the container.
The following
podman runcommand is very long and should be entered as a single line.[student@servera ~]$podman run --name myquickweb --rm registry.lab.example.com/rhel8/httpd-24:1-105 cat /etc/redhat-releaseRed Hat Enterprise Linux release 8.2 (Ootpa)Use the
podman ps -acommand to confirm that themyquickwebcontainer is deleted. Themyquickwebcontainer should not be listed in thepodman ps -acommand's output.[student@servera ~]$podman ps -a | grep myquickweb[student@servera ~]$
Perform bulk operations on existing containers using the
podmancommand:List all containers running or stopped.
Ensure that all existing containers are stopped.
Remove all containers.
Verify that all containers are removed.
List all containers, running or stopped. Your output may vary.
[student@servera ~]$podman ps -aCONTAINER ID IMAGE COMMAND 9e8f14e74fd4 registry.lab.example.com/rhel8/httpd-24:1-105 /usr/bin/run-http 6d95bd8559de registry.lab.example.com/rhel8/httpd-24:1-105 /bin/bash abcb42ef2ff1 registry.lab.example.com/rhel8/mariadb-103:1-102 run-mysqld CREATED STATUS PORTS NAMES 5 minutes ago Up 5 minutes ago mysecondweb 18 minutes ago Exited (0) 17 minutes ago myweb 26 minutes ago Exited (0) 19 minutes ago 0.0.0.0:3306->3306/tcp mydbStop all containers.
[student@servera ~]$podman stop -a6d95bd8559de81486b0876663e72260a8108d83aef5c5d660cb8f133f439c025 abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815 9e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028Remove all containers.
[student@servera ~]$podman rm -a6d95bd8559de81486b0876663e72260a8108d83aef5c5d660cb8f133f439c025 9e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028 abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815Verify that all containers have been removed.
[student@servera ~]$podman ps -aCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES[student@servera ~]$
Exit from
servera.[student@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$
This concludes the guided exercise.