Bookmark this page

Guided Exercise: Performing Advanced Container Management

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

  1. Use the ssh command to log in to servera as the student user. 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 ~]$ 
  2. Log in to the container registry using the podman login command.

    [student@servera ~]$ podman login registry.lab.example.com
    Username: admin
    Password: redhat321
    Login Succeeded!
  3. Create a detached MariaDB database container based on the specification in the following substeps using the podman run command. 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 from registry.lab.example.com, then the command will automatically pull the requested image from the registry.

    1. Create a detached container named mydb that uses the container image registry.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 user user1 (password redhat), set the root password to redhat, and create the database items.

      Variable Value
      MYSQL_USER user1
      MYSQL_PASSWORD redhat
      MYSQL_DATABASE items
      MYSQL_ROOT_PASSWORD redhat

      The following podman run command 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.txt file.

      [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-102
      Trying 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 ~]$ 
      
    2. Confirm that the container is running and publishing the correct ports using the podman ps command.

      [student@servera ~]$ podman ps
      CONTAINER 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 ago  0.0.0.0:3306->3306/tcp  mydb
      
  4. Connect to the MariaDB database in your mydb container using the mysql command. Confirm that the items database exist, and then exit from MariaDB and stop the mydb container.

    1. Connect to MariaDB as user1 with redhat as the password. Specify port 3306 and the IP address of localhost, which is your container host (127.0.0.1).

      [student@servera ~]$ mysql -u user1 -p --port=3306 --host=127.0.0.1
      Enter password: redhat
      Welcome 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)]>
      
    2. Confirm the items database exist, and then exit from MariaDB.

      MariaDB [(none)]> show databases;
      +--------------------+
      | Database           |
      +--------------------+
      | information_schema |
      | items              |
      | test               |
      +--------------------+
      3 rows in set (0.001 sec)
      
      MariaDB [(none)]> exit
      Bye
      [student@servera ~]$
      
    3. Stop the mydb container. Your container ID will be different from the following:

      [student@servera ~]$ podman stop mydb
      abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815
      
  5. 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.

    1. Create a container named myweb that is running Apache HTTP Server 2.4, and also starts an interactive shell in the container. Use the registry.lab.example.com/rhel8/httpd-24:1-105 container image. The following podman run command 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$ 
      
    2. At the interactive shell prompt in the container, run the cat /etc/redhat-release command to display the contents of the /etc/redhat-release file in the container. Exit the container.

      bash-4.4$ cat /etc/redhat-release
      Red Hat Enterprise Linux release 8.2 (Ootpa)
      bash-4.4$ exit
      exit
      [student@servera ~]$ 
      
    3. Verify that the myweb container is no longer running.

      [student@servera ~]$ podman ps -a
      CONTAINER 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 ago   Exited (0) 25 seconds ago                          myweb
      9 minutes ago         Exited (0) 3 minutes ago   0.0.0.0:3306->3306/tcp  mydb
      
  6. 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.

    1. 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-105
      9e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028
      
    2. Connect to the mysecondweb container to display the Linux name and kernel release using the podman exec command.

      [student@servera ~]$ podman exec mysecondweb uname -sr
      Linux 4.18.0-193.el8.x86_64
      
    3. Run the podman exec command 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 uptime
       00:14:53 up  2:15,  0 users,  load average: 0.08, 0.02, 0.01
      
    4. Leave the mysecondweb container running.

  7. Create a container named myquickweb that lists the contents of the /etc/redhat-release file, and then automatically exits and deletes the container. Confirm that the container is deleted.

    1. Create the container.

      The following podman run command 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-release
      Red Hat Enterprise Linux release 8.2 (Ootpa)
      
    2. Use the podman ps -a command to confirm that the myquickweb container is deleted. The myquickweb container should not be listed in the podman ps -a command's output.

      [student@servera ~]$ podman ps -a | grep myquickweb
      [student@servera ~]$
      
  8. Perform bulk operations on existing containers using the podman command:

    • List all containers running or stopped.

    • Ensure that all existing containers are stopped.

    • Remove all containers.

    • Verify that all containers are removed.

    1. List all containers, running or stopped. Your output may vary.

      [student@servera ~]$ podman ps -a
      CONTAINER 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 mydb
      
    2. Stop all containers.

      [student@servera ~]$ podman stop -a
      6d95bd8559de81486b0876663e72260a8108d83aef5c5d660cb8f133f439c025
      abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815
      9e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028
      
    3. Remove all containers.

      [student@servera ~]$ podman rm -a
      6d95bd8559de81486b0876663e72260a8108d83aef5c5d660cb8f133f439c025
      9e8f14e74fd4d82d95a765b8aaaeb1e93b9fe63c54c2cc805509017315460028
      abcb42ef2ff1b85a50e3cd9bc15877ef823979c8166d0076ce5ebc5ea19c0815
      
    4. Verify that all containers have been removed.

      [student@servera ~]$ podman ps -a
      CONTAINER ID  IMAGE  COMMAND  CREATED  STATUS  PORTS  NAMES
      [student@servera ~]$
      
  9. Exit from servera.

    [student@servera ~]$ exit
    logout
    Connection to servera closed.
    [student@workstation ~]$ 
    

Finish

On the workstation machine, run the lab containers-advanced finish script to complete this exercise.

[student@workstation ~]$ lab containers-advanced finish

This concludes the guided exercise.

Revision: rh199-8.2-3beeb12