“docker inspect” Command Examples

The “docker inspect” command is a powerful feature of Docker that allows users to retrieve low-level information about various Docker objects. It provides detailed metadata and configuration information for containers, images, volumes, networks, and other Docker entities.

When you run the “docker inspect” command, you need to specify the target object by its ID or name. Docker will then retrieve and display a JSON-formatted output containing a wide range of information related to the specified object.

Here are some key details that can be obtained through the “docker inspect” command:

  • Container Information: For a container, “docker inspect” provides details such as its ID, name, image used to create it, command executed inside the container, network settings, environment variables, exposed ports, and more. This information is useful for understanding the configuration and runtime characteristics of the container.
  • Image Details: When inspecting an image, “docker inspect” reveals information about its layers, tags, size, creation date, and associated configuration. This allows users to understand the composition and properties of an image and verify its integrity.
  • Volume Information: For volumes, “docker inspect” provides details like the volume name, mount point, volume driver used, and any associated labels. This information helps users understand the storage and persistence aspects of their Docker volumes.
  • Network Details: When inspecting a network, “docker inspect” reveals information such as the network ID, name, subnet configuration, associated containers, and any custom options applied. This enables users to understand the network configuration and connectivity between containers.
  • Service Information: In the case of Docker Swarm services, “docker inspect” provides detailed information about the service, including its name, labels, replicas, tasks, network configuration, and more. This allows users to understand the properties and status of their services within the Swarm cluster.

The output of the “docker inspect” command is in JSON format, which can be parsed and used programmatically. This flexibility enables users to extract specific information they require or integrate the command’s output into their own scripts or tools for further analysis or automation.

The “docker inspect” command is particularly useful for troubleshooting, debugging, or gaining in-depth knowledge about Docker objects. It provides a comprehensive view of the configuration and state of containers, images, volumes, networks, and services, allowing users to understand their properties, relationships, and behavior within the Docker ecosystem.

docker inspect Command Examples

1. Show help:

# docker inspect

2. Display information about a container, image, or volume using a name or ID:

# docker inspect [container|image|ID]

3. Display a container’s IP address:

# docker inspect --format='range .NetworkSettings.Networks.IPAddressend' container

4. Display the path to the container’s log file:

# docker inspect --format='.LogPath' container

5. Display the image name of the container:

# docker inspect --format='.Config.Image' container

6. Display the configuration information as JSON:

# docker inspect --format='json .Config' container

7. Display all port bindings:

# docker inspect --format='range $p, $conf := .NetworkSettings.Ports $p -> (index $conf 0).HostPort end' container

Summary

In summary, the “docker inspect” command is a valuable tool for obtaining low-level information on Docker objects. It provides detailed metadata and configuration information for containers, images, volumes, networks, and services. By using this command, users can gain a deeper understanding of their Docker environment, troubleshoot issues, and automate tasks based on the retrieved information.

Related Post