Docker Images
Estimated reading: 4 minutes 5 views

🐳 How to Inspect Docker Images – Complete Guide with Examples & FAQs

Inspecting Docker images is essential when you want to understand, debug, or optimize containerized applications. Docker provides several built-in commands that help you analyze image metadata, layers, and runtime configurations.

This guide walks you through the most effective ways to inspect Docker images β€” with real code outputs, useful tips, and clear FAQs to help you master Docker image inspection! πŸš€


🧠 What Is Docker Image Inspection?

Inspecting a Docker image means exploring its metadata, such as:

  • Base OS and image layers
  • Entrypoint and default commands
  • Environment variables
  • Labels and author info

These details help you understand how an image is constructed and how it behaves when run.


πŸ” Method 1: Using docker inspect

The docker inspect command returns detailed metadata about Docker images in JSON format.

πŸ”Ή Syntax:

docker inspect <image_name_or_id>

πŸ§ͺ Example:

docker inspect nginx

πŸ“€ Output (truncated for readability):

[
{
"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;"
]
}
}
]

βœ… Tip: Use | jq at the end to prettify and parse the JSON:

docker inspect nginx | jq

🧠 Extract Specific Info Using --format

You can filter specific data fields using the --format flag with Go templating.

🎯 Get Creation Date:

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

πŸ“€ Output:

2024-03-22T14:00:35.825Z

🎯 Get Environment Variables:

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

πŸ“€ Output:

[PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin NGINX_VERSION=1.25.3]

🎯 Get Entrypoint:

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

πŸ“€ Output:

[/docker-entrypoint.sh]

🧱 Method 2: View Layers with docker history

The docker history command shows how an image was built layer by layer.

πŸ”Ή Syntax:

docker history <image_name>

πŸ§ͺ Example:

docker history nginx

πŸ“€ Output:

IMAGE          CREATED         CREATED BY                                      SIZE      COMMENT
ad4c705f24... 3 days ago /bin/sh -c #(nop) CMD ["nginx" "-g" "daemo... 0B
<missing> 3 days ago /bin/sh -c #(nop) ENTRYPOINT ["/docker-ent... 0B
<missing> 3 days ago /bin/sh -c #(nop) ENV NGINX_VERSION=1.25.3 0B
<missing> 3 days ago /bin/sh -c set -x && addgroup ... 53.4MB
...

πŸ“Œ This is super helpful when you want to reverse-engineer how an image was built.


🏷️ Method 3: docker image inspect

This is an alias that works just like docker inspect but explicitly targets images.

πŸ§ͺ Example:

docker image inspect alpine

πŸ“€ Output (truncated):

[
{
"Id": "sha256:c1681b5f5c...",
"RepoTags": ["alpine:latest"],
"Os": "linux",
"Architecture": "amd64",
"Config": {
"Cmd": ["/bin/sh"]
}
}
]

πŸ”Ž Method 4: Explore with dive (Advanced CLI Tool)

dive is an open-source tool for exploring Docker image layers interactively.

πŸ”Ή Install Dive:

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

πŸ§ͺ Example:

dive nginx

πŸ–ΌοΈ Output:

You’ll see a terminal-based UI showing:

  • Each image layer
  • File additions/changes
  • Efficiency metrics
  • Commands used to create layers

πŸš€ Dive is perfect for optimizing and auditing Docker images.


πŸ“‹ Breakdown of Common docker inspect Fields

FieldDescription
IdUnique image hash
RepoTagsTags like nginx:latest
CreatedTimestamp of image creation
ArchitectureSystem architecture (amd64)
OsOperating system
Config.EnvList of environment variables
Config.CmdDefault command executed
Config.EntrypointEntrypoint script/command
RootFSLayer structure

πŸ§‘β€πŸ’» Final Thought

Docker image inspection is your first step to understanding what your containers are actually running. Whether you’re checking environment variables, entrypoints, or layer sizes, these tools can help you debug, optimize, and secure your Docker workflows.

πŸ” Try combining docker inspect, docker history, and dive for a full 360Β° view of your images!

πŸ™‹ Frequently Asked Questions (FAQs)

❓ Can I inspect images from Docker Hub without pulling them?

No, docker inspect works only on local images. To inspect remote images, use tools like:

  • skopeo
  • Docker Hub Web UI (for basic metadata)

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

Functionally identical for images:

  • docker inspect is universal (containers, volumes, images, etc.)
  • docker image inspect focuses solely on images.

❓ How can I find the base image?

Use:

docker history <image_name>

Look for the bottom-most layer, which often represents the base (like alpine, ubuntu, etc.).


❓ Can I view the original Dockerfile?

Not directly. Docker doesn’t store Dockerfiles in images. However:

  • docker history and dive help you reconstruct it.
  • Some maintainers include the Dockerfile in image labels or documentation.

❓ How do I list all local Docker images?

Run:

docker images

or:

docker image ls

Leave a Reply

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

Share this Doc

How to Inspect Docker Image

Or copy link

CONTENTS
Scroll to Top