Bookmark this page

Guided Exercise: Running a Basic Container

In this exercise, you will install container tools and test them by running a simple rootless container.

Outcomes

You should be able to install container management tools and use them to run a container.

On the workstation machine, log in as the student user with student as the password.

On the workstation machine, run the lab containers-basic start command. This command runs a start script to determine whether the servera machine is reachable on the network. It also checks and configures the container registry and ensures that the container image used for this exercise is stored there.

[student@workstation ~]$ lab containers-basic start

Procedure 16.1. 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. Install the container-tools Yum module using the yum command.

    [student@servera ~]$ sudo yum module install container-tools
    [sudo] password for student: student
    ...output omitted...
    Is this ok [y/N]: y
    ...output omitted...
    Complete!
  3. 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!
  4. Pull a container image from the registry with the fully qualified name using the podman pull command.

    [student@servera ~]$ podman pull registry.lab.example.com/rhel8/httpd-24:latest
    Trying to pull registry.lab.example.com/rhel8/httpd-24:latest...
    Getting image source signatures
    Copying blob 77c58f19bd6e done
    Copying blob 47db82df7f3f done
    Copying blob 9d20433efa0c done
    Copying blob 71391dc11a78 done
    Copying config 7e93f25a94 done
    Writing manifest to image destination
    Storing signatures
    7e93f25a946892c9c175b74a0915c96469e3b4845a6da9f214fd3ec19c3d7070
  5. Run a container from the image, connect it to the terminal, assign it a name, and then start an interactive bash shell using the podman run command. The latest tag is assumed since no tag is specified:

    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 /bin/bash
    bash-4.4$
  6. List running processes within the container. You will see only those processes running in the container. You will not see any other processes that are running on the server.

    bash-4.4$ ps aux
    USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
    default        1  6.6  0.1  12020  3120 pts/0    Ss   21:52   0:00 /bin/bash
    default        6  0.0  0.1  44596  3296 pts/0    R+   21:52   0:00 ps aux
  7. Display the current user name and ID inside the container.

    bash-4.4$ id
    uid=1001(default) gid=0(root) groups=0(root)
  8. Exit from the container shell.

    bash-4.4$ exit
    exit
  9. Run the httpd -v command in a container, using the rhel8/httpd-24 container image, and delete the container when the command exits:

    The following podman run command is very long and should be entered as a single line.

    [student@servera ~]$ podman run --rm registry.lab.example.com/rhel8/httpd-24 httpd -v
    Server version: Apache/2.4.37 (Red Hat Enterprise Linux)
    Server built:   Dec  2 2019 14:15:24
  10. Exit from servera.

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

Finish

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

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

This concludes the guided exercise.

Revision: rh199-8.2-3beeb12