Bookmark this page

Lab: Managing Containers with the New Runtime

Performance Checklist

In this lab, you will use the new container runtime to build and run a custom container.

Outcomes

You should be able to build and deploy a custom container using the new container runtime.

  1. Install the new container runtime software packages on servera.

    1. Log in to servera as the root user.

      [student@workstation ~]$ ssh root@servera
    2. Install the container-tools module, if not already installed.

      [root@servera ~]# yum module install container-tools
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
  2. Build a new container from scratch on servera and label it custom-container.

    1. Use buildah to create a new container from scratch.

      [root@servera ~]# buildah from scratch
      working-container
    2. List the available containers.

      [root@servera ~]# buildah containers
      CONTAINER ID  BUILDER  IMAGE ID     IMAGE NAME     CONTAINER NAME
      bc4c2a71c4c9     *                  scratch        working-container
    3. Label the newly created container custom-container.

      [root@servera ~]# buildah config --label name=custom-container working-container
    4. Inspect the container.

      [root@servera ~]# buildah inspect working-container
      ...output omitted...
          "Container": "working-container",
          "ContainerID": "bc4c2a71c4c9fbb11b7b88127a67173b82d0e4f95e7935c4a36b8d3010b8de16",
          "MountPoint": "",
          "ProcessLabel": "",
          "MountLabel": "",
          "ImageAnnotations": null,
          "ImageCreatedBy": "",
          "OCIv1": {
              "created": "2019-02-07T05:24:20.845648888Z",
              "architecture": "amd64",
              "os": "linux",
              "config": {
                  "Labels": {
                      "name": "custom-container"
      ...output omitted...
  3. Prepare the new container for installing software on servera.

    1. Mount the root file system of working-container.

      Note

      Verify the correct mount point for your case.

      [root@servera ~]# buildah mount working-container
      /var/lib/containers/storage/overlay/14e1...fbed/merged
    2. Initialize the RPM database within the container.

      [root@servera ~]# rpm --root \
      > /var/lib/containers/storage/overlay/14e1...fbed/merged \
      > --initdb
    3. Download the redhat-release-server RPM on servera.

      [root@servera ~]# yum install yum-utils
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
      [root@servera ~]# yumdownloader --destdir=/tmp redhat-release-server
      ...output omitted...
      redhat-release-8.0-0.44.el8.x86_64.rpm             3.4 MB/s |  45 kB   00:00
    4. Install the redhat-release-server RPM on working-container.

      [root@servera ~]# rpm -ivh \
      > --root /var/lib/containers/storage/overlay/14e1...fbed/merged \
      > /tmp/redhat-release*.rpm 
      ...output omitted...
      Updating / installing...
         1:redhat-release-8.0-0.44.el8      ################################# [100%]
    5. Copy the local repository file to the working-container mount point.

      [root@servera ~]# cp \
      > /etc/yum.repos.d/rhel_dvd.repo \
      > /var/lib/containers/storage/overlay/14e1...fbed/merged/etc/yum.repos.d/
  4. Customize the new container to run an apache web server, with some text content and listening on TCP port 80, on servera.

    1. Install the httpd package in the container.

      [root@servera ~]# yum install \
      > --installroot /var/lib/containers/storage/overlay/14e1...fbed/merged \
      > httpd
      ...output omitted...
      Is this ok [y/N]: y
      ...output omitted...
      Complete!
    2. Create some text content and expose it as an index.html on working-container mount directory.

      [root@servera ~]# echo "custom-container Working OK" > \
      > /var/lib/containers/storage/overlay/14e1...fbed/merged/var/www/html/index.html
    3. Configure /usr/sbin/httpd as the first command to run in working-container.

      [root@servera ~]# buildah config --cmd "/usr/sbin/httpd -DFOREGROUND" \
      > working-container
    4. Configure the internal listening port for httpd daemon in working-container.

      [root@servera ~]# buildah config --port 80/tcp working-container
    5. Clean up the Yum cache on the working-container container.

      [root@servera ~]# yum clean all \
      > --installroot /var/lib/containers/storage/overlay/14e1...fbed/merged \
      ...output omitted...
    6. Unmount the root file system of working-container.

      [root@servera ~]# buildah unmount working-container
      14e1392a5a7d06da689e26c1438b9092008f9c012affbae943ee25720ecbfbed
  5. Create a new container image based on your custom container and name it custom-image, on servera.

    1. Create the container image custom-image based on the working-container container.

      [root@servera ~]# buildah commit working-container custom-image
      Getting image source signatures
      Copying blob sha256:02f83791177ef46b84dfbf49d491971a9a83f793af08a507c1a744f842366010
       144.82 MiB / 144.82 MiB [==================================================] 9s
      Copying config sha256:09901c90da2a4ea033e8083316983605e09dd34860729f1047f2d78ecea06558
       332 B / 332 B [============================================================] 0s
      Writing manifest to image destination
      Storing signatures
      09901c90da2a4ea033e8083316983605e09dd34860729f1047f2d78ecea06558
    2. List the available images on servera.

      [root@servera ~]# buildah images
      IMAGE NAME              IMAGE TAG  IMAGE ID      CREATED AT         SIZE
      localhost/custom-image  latest     09901c90da2a  Feb 6, 2019 22:22  483 MB
  6. Deploy and test a container based on the new custom container image, on servera.

    1. Run a container based on the localhost/custom-image image.

      [root@servera ~]# podman run -d -p 80:80 --name lab-container localhost/custom-image
      1aedf5420e73b71105b02bc7fdbea406b3313ec29bde7fa3f661c1ccf4fc1a7a
    2. Test the container httpd daemon.

      [root@servera ~]# curl localhost
      custom-container Working OK
    3. Use firewalld to open the HTTP service port on servera.

      [root@servera ~]# firewall-cmd --add-service=http
      success
  7. Try accessing the web server running inside the container from serverb. When done, log off from serverb.

    1. Open a new terminal and log in to serverb as the student user.

      [student@workstation ~]$ ssh student@serverb
    2. Test the container httpd daemon inside servera.

      [student@serverb ~]$ curl http://servera
      custom-container Working OK
    3. Log off from serverb.

      [student@serverb ~]$ exit
      [student@workstation ~]$ 
  8. Clean up the exercise data on servera. When done, log off from servera.

    1. Switch to the servera terminal, and stop the running container.

      [root@servera ~]# podman stop lab-container
      1aedf5420e73b71105b02bc7fdbea406b3313ec29bde7fa3f661c1ccf4fc1a7a
    2. Delete the container on servera.

      [root@servera ~]# podman rm lab-container
      1aedf5420e73b71105b02bc7fdbea406b3313ec29bde7fa3f661c1ccf4fc1a7a
    3. Delete the container image on servera.

      [root@servera ~]# podman rmi localhost/custom-image
      a8fe25c677f2878d73ace848d7fd2f2bf06f1470c94e33fee9a444eecd8e49d9
    4. Delete the working-container container on servera.

      [root@servera ~]# buildah delete working-container
      bc4c2a71c4c9fbb11b7b88127a67173b82d0e4f95e7935c4a36b8d3010b8de16
    5. Log off from servera.

      [root@servera ~]# exit
      [student@workstation ~]$ 

This concludes the lab.

Revision: rh354-8.0-0e36520