Here’s a complete tutorial on docker inspect
, including its purpose, how it works, and a comprehensive list of examples.
What is docker inspect
?
docker inspect
is a Docker command used to retrieve detailed information about containers, images, networks, and volumes in JSON format. It provides extensive data such as configuration, networking, mounts, process details, and more.
Key Features:
- Works with containers, images, networks, and volumes.
- Returns data in JSON format.
- Ideal for debugging, auditing, and scripting.
- Supports filtering specific data with
--format
.
Basic Syntax
docker inspect [OPTIONS] NAME|ID [NAME|ID...]
Options:
--format
: Format the output using a Go template.--type
: Specify the type of object (container
,image
,network
, orvolume
).
Examples of docker inspect
1. Inspect a Running Container
docker inspect my_container
This returns the full JSON output containing all details about my_container
.
2. Inspect a Docker Image
docker inspect ubuntu
This command retrieves metadata for the ubuntu
image, including its ID, creation date, layers, and configuration.
3. Inspect a Network
docker inspect my_network
This shows details of the my_network
Docker network, such as the driver type (bridge, overlay), subnet, and connected containers.
4. Inspect a Volume
docker inspect my_volume
This retrieves information about the my_volume
volume, including its mount path and creation time.
Using --format
to Filter Specific Information
The full JSON output can be overwhelming. Use the --format
option to extract specific data using Go templates.
5. Get a Container’s IP Address
docker inspect --format='{{ .NetworkSettings.IPAddress }}' my_container
This returns only the IP address of my_container
.
6. Get a Container’s Mounts
docker inspect --format='{{ json .Mounts }}' my_container
This returns details about the container’s mounted volumes in JSON format.
7. Get the Container’s Image Name
docker inspect --format='{{ .Config.Image }}' my_container
8. Get the Image ID of an Image
docker inspect --format='{{ .Id }}' ubuntu
This returns the unique ID of the ubuntu
image.
9. Get a Container’s Environment Variables
docker inspect --format='{{ .Config.Env }}' my_container
This returns all environment variables set in my_container
.
10. Check the Restart Policy of a Container
docker inspect --format='{{ .HostConfig.RestartPolicy.Name }}' my_container
11. Get the Labels of a Container
docker inspect --format='{{ .Config.Labels }}' my_container
This returns any labels associated with the container.
12. Check the Container’s State (Running, Stopped, or Paused)
docker inspect --format='{{ .State.Status }}' my_container
This shows whether the container is running
, exited
, or paused
.
13. Inspect Multiple Containers at Once
docker inspect my_container1 my_container2
This displays detailed information about both containers.
14. Get the Path to the Container’s Log File
docker inspect --format='{{ .LogPath }}' my_container
15. Get Network Information (IP, Gateway, and Subnet)
docker inspect --format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' my_container
This command extracts the IP address from the bridge
network.
Examples of Inspecting Specific Object Types (--type
)
16. Inspect Only Containers
docker inspect --type container my_container
17. Inspect Only Networks
docker inspect --type network my_network
18. Inspect Only Images
docker inspect --type image ubuntu
Combining docker inspect
with Other Commands
19. Check if a Container is Running Before Stopping It
if [ "$(docker inspect --format='{{ .State.Running }}' my_container)" == "true" ]; then
docker stop my_container
fi
20. Monitor a Container’s CPU Usage
docker inspect --format='{{ .HostConfig.CpuShares }}' my_container
List of Common docker inspect
Commands
Command | Description |
---|---|
docker inspect my_container | Inspect a running container |
docker inspect ubuntu | Inspect a Docker image |
docker inspect my_network | Inspect a Docker network |
docker inspect my_volume | Inspect a Docker volume |
docker inspect --format='{{ .Config.Env }}' | Get environment variables from a container |
docker inspect --format='{{ .State.Status }}' | Check if a container is running, exited, or paused |
docker inspect --type network | Inspect networks only |
docker inspect --type image | Inspect images only |
Best Practices for Using docker inspect
:
- Use
--format
to filter and avoid scrolling through long JSON output. - Automate monitoring scripts using filtered
docker inspect
data. - Inspect logs and network settings for debugging.
- Combine with other Docker commands for advanced workflows.
Common Errors and Solutions
- “No such object: “
→ Ensure the container, image, or network exists. Check withdocker ps
,docker images
, ordocker network ls
. - Incorrect JSON Path with
--format
→ Verify the JSON structure using the fulldocker inspect
output before creating a custom filter.
I’m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I am working at Cotocus. I blog tech insights at DevOps School, travel stories at Holiday Landmark, stock market tips at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at I reviewed , and SEO strategies at Wizbrand.
Please find my social handles as below;
Rajesh Kumar Personal Website
Rajesh Kumar at YOUTUBE
Rajesh Kumar at INSTAGRAM
Rajesh Kumar at X
Rajesh Kumar at FACEBOOK
Rajesh Kumar at LINKEDIN
Rajesh Kumar at PINTEREST
Rajesh Kumar at QUORA
Rajesh Kumar at WIZBRAND