Fatskills
Practice. Master. Repeat.
Study Guide: Docker Docker Dockerfile and Building Images Inspecting Images docker inspect dive
Source: https://www.fatskills.com/kubernetes/chapter/docker-docker-dockerfile-and-building-images-inspecting-images-docker-inspect-dive

Docker Docker Dockerfile and Building Images Inspecting Images docker inspect dive

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~3 min read

1. Core Command / Concept

Inspecting Docker images to understand their configuration and metadata. docker inspect

2. Step‑by‑Step

  1. Run docker images to list all available images.
  2. Choose an image to inspect, e.g., docker inspect alpine.
  3. Check the output for metadata like image ID, creation date, and author.
  4. Look for the Config section to see the image's configuration.
  5. Run docker inspect -f '{{.Config.Labels}}' alpine to view only the labels.
  6. Run docker inspect -f '{{.Config.Env}}' alpine to view only the environment variables.
  7. Run docker inspect -f '{{.GraphDriver.Data}}' alpine to view the storage driver data.
  8. Clean up by removing the inspected image with docker rmi alpine.

3. Real Commands with Examples


Example 1: Inspect a Specific Image

Purpose: View the configuration of an image.
Command: docker inspect alpine Flags: -f specifies the format of the output.

Example 2: Inspect an Image with Specific Metadata

Purpose: View only the labels of an image.
Command: docker inspect -f '{{.Config.Labels}}' alpine Flags: -f specifies the format of the output, {{.Config.Labels}} extracts the labels.

Example 3: Inspect an Image with Environment Variables

Purpose: View only the environment variables of an image.
Command: docker inspect -f '{{.Config.Env}}' alpine Flags: -f specifies the format of the output, {{.Config.Env}} extracts the environment variables.

4. Common Errors


Error 1: Image Not Found

Error message: Error: No such image: alpine Why it happens: The image does not exist locally.
One-line fix: docker pull alpine to download the image.

Error 2: Inspect Command Failed

Error message: Error: failed to inspect image: Get "https://...": dial tcp: lookup ...: no such host Why it happens: The Docker daemon is not running or the image is not accessible.
One-line fix: docker daemon to start the Docker daemon.

Error 3: Invalid Flag

Error message: Error: unknown flag: -f Why it happens: The flag is not recognized.
One-line fix: docker inspect --help to view the available flags.

5. Quick Checks


Scenario 1: Inspect a Busybox Image

Situation: You want to inspect a Busybox image.
Command to run: docker inspect busybox What a correct response looks like: The image's metadata and configuration.

Scenario 2: Inspect an Image with Labels

Situation: You want to inspect an image with labels.
Command to run: docker inspect -f '{{.Config.Labels}}' alpine What a correct response looks like: The image's labels.

Scenario 3: Inspect an Image with Environment Variables

Situation: You want to inspect an image with environment variables.
Command to run: docker inspect -f '{{.Config.Env}}' alpine What a correct response looks like: The image's environment variables.

6. Last‑Minute Reference

docker inspect displays detailed information about an image.
-f flag specifies the format of the output.
{{.Config.Labels}} extracts the labels from the image's configuration.
{{.Config.Env}} extracts the environment variables from the image's configuration.
{{.GraphDriver.Data}} extracts the storage driver data from the image's configuration.
docker inspect -f '{{.Config.Labels}}' alpine views only the labels of an image.
docker inspect -f '{{.Config.Env}}' alpine views only the environment variables of an image.
docker inspect -f '{{.GraphDriver.Data}}' alpine views the storage driver data of an image.
docker rmi alpine removes the inspected image.
• ⚠️ Be cautious when removing images with docker rmi.
• ⚠️ Use docker inspect to view image metadata before removing it.
• ? Verify with 'docker version' that you are using the correct Docker version.




ADVERTISEMENT