It shows detailed low-level information about Docker objects like containers, images, volumes, or networks in JSON format.
Click to reveal answer
beginner
How can you use docker inspect to get information about a running container?
Run docker inspect <container_name_or_id> to see detailed info such as IP address, mounts, environment variables, and more.
Click to reveal answer
beginner
What format does docker inspect output its information in?
It outputs information in JSON format, which is easy to read and can be parsed by other tools.
Click to reveal answer
intermediate
How do you extract a specific piece of information, like the IP address, from docker inspect output?
Use the --format option with a Go template, for example: docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' <container>.
Click to reveal answer
beginner
Can docker inspect be used on Docker images?
Yes, you can inspect images by running docker inspect <image_name_or_id> to see metadata like layers, size, and creation time.
Click to reveal answer
What is the primary output format of the docker inspect command?
AXML
BYAML
CJSON
DPlain text
✗ Incorrect
docker inspect outputs detailed information in JSON format, which is structured and easy to parse.
Which command shows the IP address of a container named webapp?
The --format option with Go template extracts the IP address from the inspect output.
Can docker inspect be used to get details about Docker volumes?
AYes
BNo
COnly for named volumes
DOnly for volumes attached to containers
✗ Incorrect
docker inspect works on volumes, containers, images, and networks to show detailed info.
What kind of information can you NOT get from docker inspect?
AContainer logs
BContainer IP address
CImage creation time
DContainer environment variables
✗ Incorrect
Container logs are accessed with docker logs, not docker inspect.
Which of these commands will show detailed info about a Docker image named nginx?
Adocker logs nginx
Bdocker inspect nginx
Cdocker ps nginx
Ddocker run nginx
✗ Incorrect
docker inspect nginx shows metadata about the image.
Explain how to use docker inspect to find the IP address of a running container.
Think about how to filter JSON output to get just the IP.
You got /5 concepts.
Describe what kind of information you can get from docker inspect for a Docker image.
Focus on image details, not container runtime info.
You got /5 concepts.
Practice
(1/5)
1. What is the primary purpose of the docker inspect command?
easy
A. To start a new Docker container
B. To show detailed information about Docker objects like containers and images
C. To remove unused Docker images
D. To list all running Docker containers
Solution
Step 1: Understand the command's function
docker inspect is used to get detailed JSON data about Docker objects such as containers, images, volumes, and networks.
Step 2: Compare with other Docker commands
Starting containers is done with docker run, removing images with docker rmi, and listing containers with docker ps. None of these show detailed info like docker inspect.
Final Answer:
To show detailed information about Docker objects like containers and images -> Option B
Quick Check:
docker inspect = detailed info [OK]
Hint: Remember: inspect means look closely at details [OK]
Common Mistakes:
Confusing inspect with commands that start or list containers
Thinking inspect modifies containers
Assuming inspect only works for images
2. Which of the following is the correct syntax to inspect a container named myapp?
easy
A. docker inspect myapp
B. docker inspect -n myapp
C. docker inspect --container myapp
D. docker inspect container=myapp
Solution
Step 1: Recall the basic syntax of docker inspect
The command is docker inspect [OPTIONS] NAME|ID. No extra flags are needed to specify container name.
Step 2: Evaluate each option
docker inspect myapp matches the correct syntax. Options B, C, and D use invalid flags or formats not recognized by Docker.
Final Answer:
docker inspect myapp -> Option A
Quick Check:
docker inspect + container name = correct syntax [OK]
Hint: Use just 'docker inspect' plus container name or ID [OK]
Common Mistakes:
Adding unnecessary flags like -n or --container
Using equal signs in command arguments
Confusing inspect syntax with other Docker commands
3. What will be the output of the command docker inspect --format='{{.NetworkSettings.IPAddress}}' mycontainer?
medium
A. An error because the format is incorrect
B. The container's environment variables
C. The container's mounted volumes
D. The IP address assigned to the container named mycontainer
Solution
Step 1: Understand the --format option
The --format flag allows extracting specific fields from the JSON output using Go templates. Here, {{.NetworkSettings.IPAddress}} targets the container's IP address.
Step 2: Match the template to the expected output
This template returns the IP address string of the container named mycontainer. Other options like environment variables or volumes require different template paths.
Final Answer:
The IP address assigned to the container named mycontainer -> Option D
Quick Check:
--format with IPAddress = container IP [OK]
Hint: Use --format with .NetworkSettings.IPAddress for container IP [OK]
Common Mistakes:
Confusing IPAddress with environment variables
Using wrong template syntax causing errors
Expecting full JSON output instead of filtered data
4. You run docker inspect --format='{{.Config.Env}}' mycontainer but get an empty output. What is the most likely reason?
medium
A. The container has no environment variables set
B. The container name is misspelled
C. The format string is missing quotes
D. The Docker daemon is not running
Solution
Step 1: Check the format string correctness
The format string {{.Config.Env}} is valid and properly quoted, so syntax is correct.
Step 2: Consider container state and data
If the container exists and the command runs without error but returns empty, it means no environment variables were set in the container configuration.
Final Answer:
The container has no environment variables set -> Option A
Quick Check:
Empty Env output = no env vars set [OK]
Hint: Empty Env output usually means no env vars set [OK]
Common Mistakes:
Assuming empty output means syntax error
Not verifying container name correctness
Ignoring Docker daemon status errors
5. You want to list all mount points of a container named webapp using docker inspect. Which command will correctly extract this information?
hard
A. docker inspect --format='{{.MountPoints}}' webapp
B. docker inspect --format='{{.Config.Mounts}}' webapp
C. docker inspect --format='{{json .Mounts}}' webapp
D. docker inspect --format='{{.NetworkSettings.Mounts}}' webapp
Solution
Step 1: Identify the correct JSON path for mounts
The .Mounts field contains an array of mount point objects. Using {{json .Mounts}} converts this array to JSON string output.
Step 2: Evaluate other options for correctness
.Config.Mounts and .NetworkSettings.Mounts do not exist. .MountPoints is not a valid field in Docker inspect output.
Final Answer:
docker inspect --format='{{json .Mounts}}' webapp -> Option C
Quick Check:
Use {{json .Mounts}} to get mount points [OK]
Hint: Use {{json .Mounts}} to get mount info in JSON format [OK]
Common Mistakes:
Using incorrect JSON paths like .Config.Mounts
Forgetting to use json function for arrays
Assuming mount info is under NetworkSettings
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.