How to use the command 'podman image' (with examples)

How to use the command 'podman image' (with examples)

This article provides examples and explanations for using the ‘podman image’ command to manage Docker images.

Command Description

The ‘podman image’ command is used to manage Docker images. It provides functionalities to list, delete, and view the history of local Docker images. This command is part of the Podman project, an open-source container engine that allows users to run and manage containers without requiring a daemon.

Use case 1: List local Docker images

Code:

podman image ls

Motivation: Listing the local Docker images can be useful to get an overview of the images available on a system. It allows users to quickly identify the images they have and their associated tags.

Explanation:

  • podman image ls - This command lists all the local Docker images.

Example output:

REPOSITORY            TAG      IMAGE ID       CREATED        SIZE
openshift/hello-openshift   latest   0ba141a5e625   2 months ago   49.4MB
nginx                       latest   1c5fd32f9f69   2 months ago   133MB
alpine                      latest   6dbb9cc54074   3 months ago   5.6MB

Use case 2: Delete unused local Docker images

Code:

podman image prune

Motivation: Over time, local Docker images can accumulate and take up significant disk space. Removing unused images can free up disk space and improve system performance.

Explanation:

  • podman image prune - This command deletes unused local Docker images, removing any images that have no associated containers.

Example output:

Deleted Images:
  deleted: sha256:c50ff23254d597f79619b4aaf9efdd83c6c39e838a3aaf2b6e82a140097dxx37
  deleted: sha256:5waf34062341d6fdd90e89e1cd9baf6e6522f4fca276132075b64e09c3a55e27

Total reclaimed space: 2.6 MB

Use case 3: Delete all unused images (not just those without a tag)

Code:

podman image prune --all

Motivation: Sometimes, unused local Docker images can include both tagged and untagged images. The ‘–all’ option allows users to delete all unused images, regardless of whether they have tags.

Explanation:

  • --all - This option, when used with ‘podman image prune’, deletes all unused images, including both tagged and untagged images.

Example output:

Deleted Images:
  deleted: sha256:2d5be105b65301341d6fdd90e89e1cd9baf6e6522f4fca276132075b64e09c3

Total reclaimed space: 2.5 MB

Use case 4: Show the history of a local Docker image

Code:

podman image history <image>

Motivation: Understanding the history of a Docker image can provide valuable insights into its creation and maintenance. It allows users to see the individual layers that make up the image and the commands used to build it.

Explanation:

  • <image> - This argument specifies the local Docker image for which the history is to be displayed.

Example output:

IMAGE ID          CREATED       CREATED BY                                      SIZE      COMMENT
c50ff23254d5      2 months ago  /bin/sh -c #(nop)  CMD ["/hello-openshift"]    0B
4d5b0875f808      2 months ago  /bin/sh -c #(nop)  EXPOSE 8080                  0B
d96b1618eaff      2 months ago  /bin/sh -c #(nop)  ENTRYPOINT ["/hello-opens…   0B
2bb37f77f14c      2 months ago  /bin/sh -c #(nop) COPY file:6308000e101fdc1…   49.4MB    transferred 49.4MB in 0.5 seconds…
8c2e06607696      2 months ago  /bin/sh -c #(nop) COPY --chown=1001:0 "hel…   48.6MB    transferred 48.6MB in 1.0 seconds
884f47f13266      2 months ago  /bin/sh -c #(nop) WORKDIR /tmp                  0B
d28157f28828      2 months ago  /bin/sh -c #(nop) LABEL io.openshift.non-sca…   0B
b04784f55149      2 months ago  /bin/sh -c #(nop) COPY file:072c5caec6afc5c…   2.17MB    transferred 2.17MB in 0.3 seconds…
50efb7ee0f92      2 months ago  /bin/sh -c #(nop) COPY file:304a29b0c6b290d…   9.41MB    transferred 9.41MB in 1.6 seconds…
b999774f38e1      2 months ago  /bin/sh -c #(nop) COPY file:63422725d137b99…   39.5MB    transferred 39.5MB in 1.0 seconds…
20be13e8d7b6      2 months ago  /bin/sh -c #(nop) COPY dir:4be3cf28279911d2d…   0B        copied 28 files and directories 
475002e2df48      3 months ago  /bin/sh -c #(nop)  CMD ["/bin/sh"]              0B

Conclusion:

The ‘podman image’ command provides a variety of useful functionalities for managing Docker images. It allows users to list images, delete unused images, and view the history of images. By leveraging the power of this command, users can efficiently manage their Docker images and optimize system performance.

Related Posts

How to Use the Command ppmfade (with examples)

How to Use the Command ppmfade (with examples)

The ppmfade command is used to generate a transition between two PPM (Portable Pixmap) images.

Read More
How to use the command pnmtojpeg (with examples)

How to use the command pnmtojpeg (with examples)

The pnmtojpeg command is used to convert a PNM image file to the JPEG/JFIF/EXIF image format.

Read More
How to use the command "cradle" (with examples)

How to use the command "cradle" (with examples)

The “cradle” command is a PHP framework called Cradle. It provides various subcommands to perform different tasks.

Read More