Course contentsShow
← Cloud and Infrastructure
Lesson 986 of 2,98919. Container FundamentalsFree lesson

Inspecting Image Layers

Using tools to examine layer contents, history, and commands that created each layer.

Inspecting Image Layers

You'll learn how to use container tools to peek inside image layers, see their contents, and understand the exact commands that built each one.

Why Inspection Matters

You've learned that container images are built from stacked layers, but what's actually in those layers? Inspecting them lets you understand how an image was constructed, troubleshoot bloat issues, verify security, and optimize your own builds.

Think of it like examining a sandwich: you can see each ingredient added layer-by-layer, who put it there, and how much space each takes up.

Common Inspection Tools

Most container runtimes provide commands to examine images:

  • docker history <image> shows each layer's creation command, size, and timestamp in reverse chronological order
  • docker inspect <image> reveals detailed JSON metadata including layer digests, environment variables, and configuration
  • docker image save exports the full image as a tarball you can extract and explore manually

Third-party tools like dive offer interactive exploration, showing file-system changes in each layer side-by-side with the commands that created them.

What You Can Discover

Inspecting reveals:

  • Command history: the exact RUN, COPY, and ADD instructions from the build
  • Layer sizes: which steps consume the most space
  • File additions/modifications: what changed at each step
  • Base image lineage: parent layers your image inherited
  • Unnecessary artifacts: temporary files accidentally committed to layers

This visibility helps you spot inefficiencies—like a layer that downloaded packages but didn't clean up cached files—and understand third-party images before running them in production.

Key Takeaway:
Inspecting image layers with tools like docker history and docker inspect exposes the build commands, file changes, and size of each layer, helping you optimize, debug, and verify images.