0
0
DockerHow-ToBeginner · 3 min read

How to See Image Layers in Docker: Commands and Examples

To see image layers in Docker, use the docker history IMAGE_NAME command to list all layers with their sizes and creation times. For detailed metadata about each layer, use docker inspect IMAGE_NAME.
📐

Syntax

The main commands to view Docker image layers are:

  • docker history IMAGE_NAME: Shows a list of layers with size and creation info.
  • docker inspect IMAGE_NAME: Provides detailed JSON metadata about the image and its layers.

Replace IMAGE_NAME with your Docker image's name or ID.

bash
docker history IMAGE_NAME

docker inspect IMAGE_NAME
💻

Example

This example shows how to list layers of the official nginx image using docker history. It displays each layer's ID, creation time, size, and command used.

bash
docker history nginx
Output
IMAGE CREATED CREATED BY SIZE COMMENT <missing> 2 weeks ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemon off;"] 0B <missing> 2 weeks ago /bin/sh -c #(nop) EXPOSE 80 0B <missing> 2 weeks ago /bin/sh -c #(nop) STOPSIGNAL SIGTERM 0B <missing> 2 weeks ago /bin/sh -c #(nop) ENTRYPOINT ["docker-entrypoint.sh"] 0B <missing> 2 weeks ago /bin/sh -c #(nop) COPY file:abcdef1234567890… 133MB <missing> 2 weeks ago /bin/sh -c #(nop) LABEL maintainer=NGINX Docker Maintainers 0B
⚠️

Common Pitfalls

Common mistakes when viewing Docker image layers include:

  • Using image names that do not exist locally, causing errors.
  • Expecting docker history to show detailed file changes; it only shows layer metadata.
  • Confusing image IDs with container IDs; they are different.

Always pull the image first if it is not local using docker pull IMAGE_NAME.

bash
docker history unknown-image
# Error: No such image: unknown-image

# Correct usage:
docker pull nginx
docker history nginx
📊

Quick Reference

Summary tips for viewing Docker image layers:

  • docker history IMAGE_NAME: Quick layer list with sizes and commands.
  • docker inspect IMAGE_NAME: Detailed JSON info including layer digests.
  • Use docker pull IMAGE_NAME to ensure the image is local.
  • Layer IDs in docker history may show as <missing> if layers are shared or cached.

Key Takeaways

Use docker history IMAGE_NAME to see a list of image layers with size and creation info.
Use docker inspect IMAGE_NAME for detailed metadata about image layers in JSON format.
Pull the image first with docker pull IMAGE_NAME if it is not available locally.
Layer IDs may appear as due to caching or shared layers.
docker history shows metadata, not file-level changes inside layers.