How to Inspect Docker Image: Commands and Examples
Use the
docker image inspect <image_name_or_id> command to view detailed information about a Docker image. This command shows metadata like layers, environment variables, and configuration in JSON format.Syntax
The basic syntax to inspect a Docker image is:
docker image inspect <image_name_or_id>: Shows detailed JSON metadata of the specified image.<image_name_or_id>can be the image name, tag, or image ID.
bash
docker image inspect <image_name_or_id>
Example
This example inspects the official nginx image to show its metadata including layers, environment variables, and entrypoint.
bash
docker image inspect nginx:latest
Output
[
{
"Id": "sha256:...",
"RepoTags": ["nginx:latest"],
"Created": "2024-06-01T12:00:00Z",
"ContainerConfig": {
"Env": ["PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"],
"Entrypoint": ["/docker-entrypoint.sh"]
},
"RootFS": {
"Layers": [
"sha256:layer1",
"sha256:layer2"
]
}
}
]
Common Pitfalls
Common mistakes when inspecting Docker images include:
- Using
docker inspectwithout specifyingimageorcontainer, which defaults to containers and may cause confusion. - Trying to inspect an image that is not downloaded locally, resulting in an error.
- Expecting a simple text output instead of JSON, which requires parsing or formatting tools.
Correct usage always includes docker image inspect for images.
bash
docker inspect nginx
# Wrong: Inspects container named nginx if exists, not image
docker image inspect nginx
# Correct: Inspects the nginx imageQuick Reference
Summary tips for inspecting Docker images:
- Use
docker image inspect <image>to get JSON metadata. - Image names can include tags like
nginx:latestor IDs. - Use tools like
jqto parse JSON output for readability. - Ensure the image is downloaded locally before inspecting.
Key Takeaways
Use 'docker image inspect ' to view detailed image metadata in JSON format.
Always specify 'image' in the command to avoid inspecting containers by mistake.
The image must be present locally to inspect it successfully.
JSON output can be parsed with tools like 'jq' for easier reading.
Inspecting images helps understand their configuration, layers, and environment.