MYHOSPITALNOW.COM

Find Trusted Doctors & Hospitals

Discover healthcare providers, compare hospitals, and explore treatment options worldwide.

Free Treatment Quotes • Doctor Search • Hospital Comparison

Find Healthcare Options

www.myhospitalnow.com

docker inspect tutorial: format, type options and full 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 Rajesh Kumar, a DevOps, SRE, DevSecOps, Cloud, and Platform Engineering expert passionate about sharing practical knowledge, real-world experiences, and industry best practices. I have worked at Cotocus and regularly write about technology, travel, investing, health, product reviews, and digital marketing through my various platforms. I publish technical articles at DevOps School, travel stories at Holiday Landmark, stock market insights at Stocks Mantra, health and fitness guidance at My Medic Plus, product reviews at TrueReviewNow, and SEO and digital marketing strategies at Wizbrand.

Related Posts

Debug for Docker Container

To debug a Docker container, check its state and logs first, then its network configuration, then test connectivity from another container on the same network. This page…

Read More

Install Jenkins with Docker: Persistent Setup, Port Mapping, and Logs

Learn how to run Jenkins in Docker with correct port mapping, persistent storage, and operational commands. This updated guide keeps the original workflow but adds modern, production-minded practices.

Read More

How to Access a Running Docker Container Shell: docker exec vs docker attach

Need a shell inside a running container that is already in detached mode? This updated guide shows the correct workflow, compares docker exec and docker attach, and explains when SSH does and does not make sense.

Read More

Install Atlassian Jira with Docker: Quick Start, Persistent Volumes, and Deployment Checks

This guide shows how to run Jira in Docker using the original one-line command, then improve it with persistent storage and repeatable deployment steps. It also includes a workflow diagram, command examples, and practical validation checks.

Read More

Install Sonatype Nexus with Docker: RM2/RM3 Commands, Validation Steps, and Important Caveats

A structured, production-minded rewrite of the original 2016 Docker setup for Sonatype Nexus Repository Manager 2 and 3. Includes command examples, a workflow diagram, and clear warnings about outdated tags/endpoints.

Read More

Top 5 DevOps Tools To Learn Before Writing Your Dissertation

Writing a technical dissertation is rarely just an exercise in reading sources and formatting chapters. On paper, that sounds like the job. In reality, students in computer…

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