By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.
Inspecting Docker images to understand their configuration and metadata. docker inspect
docker images
docker inspect alpine
Config
docker inspect -f '{{.Config.Labels}}' alpine
docker inspect -f '{{.Config.Env}}' alpine
docker inspect -f '{{.GraphDriver.Data}}' alpine
docker rmi alpine
Purpose: View the configuration of an image.Command: docker inspect alpine Flags: -f specifies the format of the output.
-f
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.
{{.Config.Labels}}
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.
{{.Config.Env}}
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: No such image: alpine
docker pull alpine
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: failed to inspect image: Get "https://...": dial tcp: lookup ...: no such host
docker daemon
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.
Error: unknown flag: -f
docker inspect --help
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.
docker inspect busybox
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.
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.
• 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.
docker inspect
{{.GraphDriver.Data}}
docker rmi
Join 4M+ learners. Unlock unlimited quizzes, wrong-answer tracking, flashcards + reminders, study guides, and 1-on-1 challenges.