Bookmark this page

Guided Exercise: Creating Containers with Podman

Use Podman to pull container images from a registry and to use them to run containers.

Outcomes

You should be able to run containers in Podman by using the podman run command.

As the student user on the workstation machine, use the lab command to prepare your system for this exercise.

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

Instructions

  1. Use the registry.lab.example.com/ubi9/ubi image to create a new container that prints the Hello Red Hat text.

    1. Log in to the classroom registry. Use admin as the username, and redhat321 as the password.

      [student@workstation ~]$ podman login registry.lab.example.com --tls-verify=false
      Username: admin
      Password: redhat321
      Login Succeeded!
    2. Use the podman pull command to fetch the image from the registry.

      [student@workstation ~]$ podman pull registry.lab.example.com/ubi9/ubi \
       --tls-verify=false
      Trying to pull registry.lab.example.com/ubi9/ubi:latest...
      ...output omitted...
      Getting image source signatures
      Copying blob 1153e061da4e done
      Copying config 8d2a8803cf done
      Writing manifest to image destination
      8d2a8803cfca17a81eb9412e1f33ae1c6fe3797553e9b819899dc03f1657cf12
    3. Use the podman images command to verify that the image is available locally.

      [student@workstation ~]$ podman images
      REPOSITORY                         TAG         IMAGE ID      CREATED       SIZE
      registry.lab.example.com/ubi9/ubi  latest      8d2a8803cfca  3 months ago  219 MB
    4. In a command line terminal, use podman run to create a new container. Provide an echo command to be executed inside the container.

      [student@workstation ~]$ podman run --rm registry.lab.example.com/ubi9/ubi \
       echo 'Hello Red Hat'
      Hello Red Hat
    5. Verify that the container is not running after the execution finishes.

      [student@workstation ~]$ podman ps
      CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES
  2. Explore setting and printing environment variables by using the registry.lab.example.com/ubi9/ubi container image.

    1. Use the -e option in the podman run command to set environment variables. Use the printenv command that is packaged in the container image to print the values of the environment variables.

      [student@workstation ~]$ podman run --rm -e GREET=Hello -e NAME='Red Hat' \
       registry.lab.example.com/ubi9/ubi printenv GREET NAME
      Hello
      Red Hat
    2. Verify that the container is not running after the execution finishes.

      [student@workstation ~]$ podman ps
      CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES
  3. Use the registry.lab.example.com/rhel9/httpd-24 image to run a new container that creates an Apache HTTP server.

    1. Use the podman pull command to fetch the image from the registry.

      [student@workstation ~]$ podman pull registry.lab.example.com/rhel9/httpd-24 \
       --tls-verify=false
      Trying to pull registry.lab.example.com/rhel9/httpd-24:latest...
      ...output omitted...
      Copying blob 358ca3c2eaff done
      Copying blob e584cd196457 done
      Copying config a42923e055 done
      Writing manifest to image destination
      a42923e05589d2d10c25e87736bc3b9537c38c2a6a87f37e9a71e288b01738a6
    2. Use the podman run command to start the httpd container. Use the -p option in the podman run command to redirect traffic from port 8080 on your machine to port 8080 inside the container.

      [student@workstation ~]$ podman run --rm -p 8080:8080 \
       registry.lab.example.com/rhel9/httpd-24
      => sourcing 10-set-mpm.sh ...
      => sourcing 20-copy-config.sh ...
      => sourcing 40-ssl-certs.sh ...
      ---> Generating SSL key pair for httpd...
      ...output omitted...
      [Thu Jun 06 00:02:06.591391 2024] [mpm_event:notice] [pid 1:tid 1] AH00489: Apache/2.4.57 (Red Hat Enterprise Linux) OpenSSL/3.0.7 configured -- resuming normal operations
      [Thu Jun 06 00:02:06.591430 2024] [core:notice] [pid 1:tid 1] AH00094: Command line: 'httpd -D FOREGROUND'

      The container keeps running and the logs are displayed in your terminal.

    3. In a web browser, navigate to http://localhost:8080. Verify that the HTTP server is running at the 8080 port.

    4. Go back to your command-line terminal. Press Ctrl+C to stop the container.

      ...output omitted...
      ^C
      [Thu Jun 06 00:04:13.467695 2024] [mpm_event:notice] [pid 1:tid 1] AH00491: caught SIGTERM, shutting down
    5. Create the container again by adding the -d option. The container runs in the background.

      [student@workstation ~]$ podman run --rm -d \
       -p 8080:8080 registry.lab.example.com/rhel9/httpd-24
      08ac7ce948feb65f76f82305d556843a898b60200f5b4f37d1ecb8ea381199ff
    6. Verify that the container is running in the background.

      [student@workstation ~]$ podman ps
      CONTAINER ID  IMAGE                                           COMMAND               CREATED             STATUS             PORTS                   NAMES
      08ac7ce948fe  registry.lab.example.com/rhel9/httpd-24:latest  /usr/bin/run-http...  21 seconds ago  Up 22 seconds  0.0.0.0:8080->8080/tcp  charming_tharp
  4. Use Podman Desktop to list images and containers.

    1. Open Podman Desktop. Click Activities at the upper-left corner of the top bar, and then click the Podman Desktop icon.

    2. Click Containers in the Podman Desktop navigation panel. The list includes the containers that you created in the exercise. Verify that the Apache HTTP container is running.

    3. Click Images. The list of local images displays the ubi9/ubi and the rhel9/httpd-24 images.

  5. Use Podman Desktop to start another Apache HTTP container that maps its port to port 8090 in the workstation.

    1. Click the arrow () of the rhel9/httpd-24 image to run a new container based on this image.

    2. In the container creation form, enter the following values:

      • Container name: desktop-test

      • Local port for 8080/tcp: 8090

      • Local port for 8443/tcp: 8443

    3. Click Start Container.

      Note

      You can safely ignore the SELinux security warning that displays at the top of the desktop.

    4. Navigate to the containers menu and verify that the desktop-test container is running.

    5. In the desktop-test container, click the vertical ellipsis icon () on the right, select Open Browser, and then click Yes in the confirmation dialog box.

    6. Verify that the browser can access the HTTP server at http://localhost:8090.

    7. Return to Podman Desktop. In the desktop-test container, click the Delete Container icon to delete the container, and then close Podman Desktop.

Finish

On the workstation machine, use the lab command to complete this exercise. This is important to ensure that resources from previous exercises do not impact upcoming exercises.

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

Revision: rh134-9.3-5fd2368