Docker Images
Estimated reading: 4 minutes 42 views

πŸ” How to Inspect Docker Images – Complete Guide with Commands, Tools & FAQs

🧲 Introduction – Why Inspect Docker Images?

When working with containerized applications, understanding what’s inside your Docker images is essential. Whether you’re debugging, optimizing for performance, or validating configurations before production, Docker image inspection provides deep insights into how containers are built and behave.

🎯 In this guide, you’ll learn:

  • How to view metadata and runtime settings of images
  • Methods to analyze image history and layers
  • Tools for deep inspection and optimization

πŸ”§ Method 1: Use docker inspect to View Image Metadata

The docker inspect command returns raw JSON metadata for a Docker image.

βœ… docker inspect Syntax

docker inspect <image_name_or_id>

πŸ“Œ docker inspect Example

docker inspect nginx

πŸ“€ docker inspect Sample Output (simplified):

[
  {
    "Id": "sha256:ad4c705f24...",
    "RepoTags": ["nginx:latest"],
    "Created": "2024-03-22T14:00:35.825Z",
    "Architecture": "amd64",
    "Os": "linux",
    "Config": {
      "Env": [
        "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
        "NGINX_VERSION=1.25.3"
      ],
      "Entrypoint": ["/docker-entrypoint.sh"],
      "Cmd": ["nginx", "-g", "daemon off;"]
    }
  }
]

βœ… Pro Tip: Use jq for pretty-printing:

docker inspect nginx | jq

🎯 Use --format to Extract Specific Info

docker inspect supports Go templating to extract values.

πŸ“… Get Creation Date

docker inspect --format='{{.Created}}' nginx

🌿 Get Environment Variables

docker inspect --format='{{.Config.Env}}' nginx

πŸ› οΈ Get Entrypoint Script

docker inspect --format='{{.Config.Entrypoint}}' nginx

🧱 Method 2: Use docker history to See Image Layers

The docker history command shows how an image was built, step-by-step.

βœ… docker history Syntax

docker history <image_name>

πŸ“Œ docker history Example

docker history nginx

πŸ“€ docker history Output

IMAGE          CREATED        CREATED BY                                      SIZE      COMMENT
ad4c705f24...  3 days ago     CMD ["nginx" "-g" "daemon off;"]               0B
<missing>      3 days ago     ENTRYPOINT ["/docker-entrypoint.sh"]           0B
<missing>      3 days ago     ENV NGINX_VERSION=1.25.3                        0B
<missing>      3 days ago     addgroup ...                                   53.4MB

🎯 Useful for debugging or understanding how a base image was layered and configured.


🏷️ Method 3: Use docker image inspect

docker image inspect is an alias for docker inspect but explicitly targets Docker images.

πŸ“Œ docker image inspect Example

docker image inspect alpine

βœ… Produces the same metadata fields, focused on image-level attributes.


🧰 Method 4: Explore Image Layers with dive (Advanced)

dive is an open-source CLI tool to inspect and analyze image layers interactively.

πŸ§ͺ Install Dive

sudo apt install dive       # Ubuntu/Debian
brew install dive           # macOS

πŸ“Œ Run Dive

dive nginx

πŸ–₯️ This opens a terminal UI showing:

  • Each image layer
  • File size and changes per layer
  • Efficiency score
  • Commands used to build each layer

🧠 Best For: Performance optimization and layer-level security audits.


πŸ“‹ Key Metadata Fields to Understand

FieldDescription
IdUnique image identifier (hash)
RepoTagsList of tags (e.g., nginx:latest)
CreatedTimestamp of when the image was created
OsOperating system (linux, windows)
ArchitectureSystem architecture (amd64, arm64)
Config.EnvDefined environment variables
Config.CmdDefault command executed inside the container
Config.EntrypointEntrypoint script or binary

πŸ“Œ Summary – How to Inspect Docker Image

Inspecting Docker images is a crucial step in building reliable, secure, and efficient containers. Whether you’re troubleshooting a deployment, reverse-engineering an image, or ensuring best practices, these tools empower you to understand every layer of your containers.

πŸ” Key Takeaways:

  • Use docker inspect for full metadata
  • Use --format for filtering specific fields
  • Use docker history for build step analysis
  • Use dive to explore, analyze, and optimize image layers

βš™οΈ Image inspection is especially valuable in CI/CD, production auditing, and compliance validation.


❓ Frequently Asked Questions (FAQs)

Can I inspect a Docker image without pulling it?

βœ… No, you must pull the image first. For remote inspection, use tools like:


What’s the difference between docker inspect and docker image inspect?

βœ… Both are functionally the same for images:

  • docker inspect is universal (containers, volumes, networks)
  • docker image inspect is image-specific

How do I find the base image used?

βœ… Use:

docker history <image_name>

The bottom-most layer usually indicates the base image (e.g., ubuntu, alpine).


Can I view the original Dockerfile from an image?

βœ… Not directly. Docker doesn’t save the original Dockerfile, but you can:

  • Use docker history or dive to reconstruct build steps
  • Check image labels or upstream documentation

How do I list all Docker images locally?

docker images

Or:

docker image ls

Share Now :

Leave a Reply

Your email address will not be published. Required fields are marked *

Share

How to Inspect Docker Image

Or Copy Link

CONTENTS
Scroll to Top