Skip to main content
Understanding how Docker images are built from multiple layers can help you optimize, debug, and secure your container workflows. In this guide, we’ll explore essential Docker CLI commands to:
  • List local images
  • Examine image history
  • Inspect detailed metadata
  • Filter output with JSONPath

Table of Contents

  1. Prerequisites
  2. Listing Local Images
  3. Viewing Image History
  4. Inspecting Image Metadata
  5. Filtering with JSONPath
  6. References

Prerequisites

Ensure you have Docker installed and running. Check your version with docker version.
For full installation steps, visit the Docker Docs.

Listing Local Images

To see all images stored on your host machine, use:
Example output:

Viewing Image History

Examining an image’s history reveals each layer and the command that created it. This is especially valuable if the Dockerfile isn’t available.
Sample output:

Inspecting Image Metadata

The inspect command returns comprehensive image metadata in JSON format, including environment variables, exposed ports, volumes, and more.
Abbreviated example:
Inspecting very large images may output extensive JSON. Use filtering (see next section) or redirect output to a file:

Filtering with JSONPath

Docker’s inspect supports the -f flag with JSONPath templates to extract specific fields.

Common Filters

Retrieving Exposed Ports

To list all ports exposed by an image:
Example output:

References

Watch Video