Bookmark this page

Guided Exercise: Managing Images

Learn to manage container images.

Outcomes

You should be able to manage images by performing common operations such as:

  • Creating images

  • Listing images

  • Inspecting images

  • Tagging images

  • Removing images

  • Searching images

  • Pulling images

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

This command copies an example Containerfile that you use to build the simple-server image.

[student@workstation]$ lab start images-managing

Instructions

  1. Verify that the simple-server image is not present on your machine.

    [student@workstation ~]$ podman image ls --format "{{.Repository}}"
    no output expected

    Note

    You might see images from previous exercises if you did not run the lab finish scrips.

  2. Build and run the simple-server image by using the ~/DO188/labs/images-managing/Containerfile file.

    1. Change to the exercise directory and examine its contents.

      [student@workstation ~] cd ~/DO188/labs/images-managing
      no output expected
    2. Use the exercise Containerfile and the podman build command to create the image. Use the -t option to call the image simple-server.

      [student@workstation images-managing]$ podman build -f Containerfile -t \
      simple-server
      ...output omitted...
      Successfully tagged localhost/simple-server:latest
      87dc...fc02
    3. Use the podman image ls command to verify that the simple-server image is present.

      [student@workstation images-managing]$ podman image ls
      REPOSITORY                   TAG        IMAGE ID      CREATED         SIZE
      localhost/simple-server      latest     87dc46f07c8c  5 minutes ago   892 MB

      Because you did not provide a server name and a tag to the simple-server image name, the image uses the localhost registry server and the latest tag by default.

    4. Create a container from the simple-server image and call it http-server. Use the -d option to run it in the background and the -p option to map your local host port 8080 to the container port 8000.

      [student@workstation images-managing]$ podman run -d \
        -p 8080:8000 \
        --name http-server \
        simple-server
      2b81..0207
    5. Use a tool such as curl or a web browser to send a request to http://localhost:8080/hello.html.

      [student@workstation images-managing]$ curl http://localhost:8080/hello.html
      Hello from the container
  3. Inspect the simple-server image to see which command it runs by default.

    Verify that python -m http.server is the default command for this image. This Python command comes from the CMD instruction in the exercise Containerfile.

    [student@workstation images-managing]$ podman image inspect simple-server \
      --format="{{.Config.Cmd}}"
    [/bin/sh -c python -m http.server]
  4. Tag the simple-server image with the 0.1 tag and list the images to verify the result.

    [student@workstation images-managing]$ podman image tag simple-server \
    simple-server:0.1
    no output expected

    When you list the images in your machine you can see that simple-server shows for the latest tag, and also for the 0.1 tag. Verify that the IMAGE ID has the same value because both tags point to the same image.

    [student@workstation images-managing]$ podman image ls
    REPOSITORY                  TAG       IMAGE ID      CREATED        SIZE
    localhost/simple-server     latest    87dc46f07c8c  10 minutes ago 892 MB
    localhost/simple-server     0.1       87dc46f07c8c  10 minutes ago 892 MB
  5. Remove the simple-server image completely from your system.

    1. Use the podman image rm command to remove the simple-server.

      [student@workstation images-managing]$ podman image rm simple-server
      Untagged: localhost/simple-server:latest

      The previous command only removed the latest tag because you did not specify the tag in the command and you have two tags pointing to the same image.

    2. Try to delete the simple-server:0.1 tag to remove the simple-server image completely.

      [student@workstation images-managing]$ podman image rm simple-server:0.1
      Error: Image used by 1bd7...250d: image is in use by a container

      The error message indicates that you cannot remove an image that is currently being used by a container. Before removing the image you must stop and remove the container.

    3. Force the container and container image deletion.

      [student@workstation images-managing]$ podman image rm -f simple-server:0.1
      WARN[0010] StopSignal SIGTERM failed to stop container http-server in 10 seconds, resorting to SIGKILL
      Untagged: localhost/simple-server:0.1
      Deleted: 87dc...fc02
      Deleted: 2318...7bbb

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 images-managing

Revision: do188-4.14-8c43a16