Find the Best Cosmetic Hospitals

Explore trusted cosmetic hospitals and make a confident choice for your transformation.

โ€œInvest in yourself โ€” your confidence is always worth it.โ€

Explore Cosmetic Hospitals

Start your journey today โ€” compare options in one place.

Docker commands Guide – docker inspect with examples

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, or volume).

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
Code language: JavaScript (javascript)

This returns only the IP address of my_container.


6. Get a Containerโ€™s Mounts

docker inspect --format='{{ json .Mounts }}' my_container
Code language: JavaScript (javascript)

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
Code language: JavaScript (javascript)

8. Get the Image ID of an Image

docker inspect --format='{{ .Id }}' ubuntu
Code language: JavaScript (javascript)

This returns the unique ID of the ubuntu image.


9. Get a Containerโ€™s Environment Variables

docker inspect --format='{{ .Config.Env }}' my_container
Code language: JavaScript (javascript)

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
Code language: JavaScript (javascript)

11. Get the Labels of a Container

docker inspect --format='{{ .Config.Labels }}' my_container
Code language: JavaScript (javascript)

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
Code language: JavaScript (javascript)

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
Code language: JavaScript (javascript)

15. Get Network Information (IP, Gateway, and Subnet)

docker inspect --format='{{ .NetworkSettings.Networks.bridge.IPAddress }}' my_container
Code language: JavaScript (javascript)

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
Code language: CSS (css)

20. Monitor a Containerโ€™s CPU Usage

docker inspect --format='{{ .HostConfig.CpuShares }}' my_container
Code language: JavaScript (javascript)

List of Common docker inspect Commands

CommandDescription
docker inspect my_containerInspect a running container
docker inspect ubuntuInspect a Docker image
docker inspect my_networkInspect a Docker network
docker inspect my_volumeInspect 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 networkInspect networks only
docker inspect --type imageInspect images only

Best Practices for Using docker inspect:

  1. Use --format to filter and avoid scrolling through long JSON output.
  2. Automate monitoring scripts using filtered docker inspect data.
  3. Inspect logs and network settings for debugging.
  4. Combine with other Docker commands for advanced workflows.

Common Errors and Solutions

  1. “No such object: “
    โ†’ Ensure the container, image, or network exists. Check with docker ps, docker images, or docker network ls.
  2. Incorrect JSON Path with --format
    โ†’ Verify the JSON structure using the full docker inspect output before creating a custom filter.

Find Trusted Cardiac Hospitals

Compare heart hospitals by city and services โ€” all in one place.

Explore Hospitals
Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at <a href="https://www.cotocus.com/">Cotocus</a>. I share tech blog at <a href="https://www.devopsschool.com/">DevOps School</a>, travel stories at <a href="https://www.holidaylandmark.com/">Holiday Landmark</a>, stock market tips at <a href="https://www.stocksmantra.in/">Stocks Mantra</a>, health and fitness guidance at <a href="https://www.mymedicplus.com/">My Medic Plus</a>, product reviews at <a href="https://www.truereviewnow.com/">TrueReviewNow</a> , and SEO strategies at <a href="https://www.wizbrand.com/">Wizbrand.</a> Do you want to learn <a href="https://www.quantumuting.com/">Quantum Computing</a>? <strong>Please find my social handles as below;</strong> <a href="https://www.rajeshkumar.xyz/">Rajesh Kumar Personal Website</a> <a href="https://www.youtube.com/TheDevOpsSchool">Rajesh Kumar at YOUTUBE</a> <a href="https://www.instagram.com/rajeshkumarin">Rajesh Kumar at INSTAGRAM</a> <a href="https://x.com/RajeshKumarIn">Rajesh Kumar at X</a> <a href="https://www.facebook.com/RajeshKumarLog">Rajesh Kumar at FACEBOOK</a> <a href="https://www.linkedin.com/in/rajeshkumarin/">Rajesh Kumar at LINKEDIN</a> <a href="https://www.wizbrand.com/rajeshkumar">Rajesh Kumar at WIZBRAND</a> <a href="https://www.rajeshkumar.xyz/dailylogs">Rajesh Kumar DailyLogs</a>

Related Posts

Docker Tutorials: Docker Image – Understanding Dockerfiles instructions & options

Hereโ€™s a step-by-step tutorial for Dockerfile, including explanations and examples for each major command. Dockerfile Tutorial A Dockerfile is a text file containing instructions to build a…

Read More

Docker Tutorials: Docker Image – Example and Sample Programs of Dockerfile

Reference Rajesh Kumar Iโ€™m a DevOps/SRE/DevSecOps/Cloud Expert passionate about sharing knowledge and experiences. I have worked at Cotocus. I share tech blog at DevOps School, travel stories…

Read More

Docker Tutorials: Installation and Configurations

Docker Installation in Centos/RHEL Method -1: How to install Docker Community Edition via YUM? Step 1 – Install required packages. yum-utils provides the yum-config-manager utility, and device-mapper-persistent-data…

Read More

Docker Tutorials: How to Install Docker in Ubuntu?

Install Docker Engine in Ubuntu NOTE – All commands you must run as root user or add a current user into a linux group name called “docker”…

Read More

Docker Lab, Excercise & Assignment – 7 – Docker Volume

Below is a very detailed tutorial and lab manual for learning Docker Volumes, using the Ubuntu image for practical, hands-on labs. This covers all major types of…

Read More

Docker Lab, Excercise & Assignment – 4 – Docker Networking

Hereโ€™s an in-depth, step-by-step tutorial and lab manual for Docker Networkingโ€”starting from basics, covering all core concepts, and providing a hands-on guide to every feature and command….

Read More
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x