Docker provides a set of commands that allow you to inspect and retrieve the metadata of your containers. Here are some of the most commonly used commands:
docker inspect
The docker inspect
command is the primary tool for inspecting the metadata of a Docker container. It returns a JSON-formatted output containing detailed information about the container, including its configuration, status, and network settings.
docker inspect <container_id_or_name>
The output of docker inspect
can be filtered and formatted using the --format
or -f
flag to extract specific pieces of information.
docker inspect -f '{{.State.Running}}' <container_id_or_name>
docker ps
The docker ps
command lists all running containers, and can be used to retrieve basic metadata about them, such as the container ID, image, command, creation time, and status.
docker ps
To display additional metadata, you can use the --format
flag to customize the output:
docker ps --format "{{.ID}}\t{{.Image}}\t{{.Status}}"
docker stats
The docker stats
command provides real-time monitoring of resource usage for one or more containers, including CPU, memory, network, and block I/O utilization.
docker stats <container_id_or_name>
This information can be useful for understanding the resource requirements and performance characteristics of your containers.
docker history
The docker history
command shows the history of changes made to a Docker image, including the metadata associated with each layer, such as the command, size, and timestamp.
docker history <image_name>
This can be helpful for understanding the composition and evolution of the images used to create your containers.
By mastering these Docker commands, you can effectively inspect and leverage the metadata of your containers to troubleshoot issues, optimize resource usage, and gain deeper insights into your containerized applications.