Docker Certified Associate Exam Course

Docker Engine

Inspecting a Container

In this guide, you’ll learn how to explore and troubleshoot Docker containers by using built-in inspection commands. We’ll cover:

  • Listing containers
  • Retrieving detailed JSON metadata
  • Monitoring live resource usage
  • Viewing in-container processes
  • Fetching and streaming logs
  • Streaming Docker system events

1. List Running Containers

Before diving deeper, get a quick overview of containers on your host:

docker container ls

You can extend this with flags:

CommandDescription
docker container lsShow running containers
docker container ls -aInclude stopped containers
docker container ls --filterFilter by status, name, label, etc.

2. Inspect Container Details

To view in-depth information—configuration, network settings, volumes—use:

docker container inspect <container_name_or_ID>

This outputs a JSON array. Example:

[
  {
    "Id": "59aa5eacd88c42970754cd6005ce315944a2efcd32288df998b29267ae54c152",
    "Created": "2020-01-14T13:23:01.225868339Z",
    "Path": "/bin/bash",
    "Args": [],
    "State": {
      "Status": "running",
      "Running": true,
      "Paused": false,
      "Restarting": false,
      "IPAddress": "172.17.0.5",
      "IPPrefixLen": 16,
      "MacAddress": "02:42:ac:11:00:05"
    }
  }
]
JSON FieldDescription
IdUnique container identifier
CreatedTimestamp when the container was instantiated
PathEntrypoint command executed in the container
ArgsArguments passed to the entrypoint
StateCurrent runtime status and networking information

Note

Use -f json to pipe this output into jq or other JSON parsers for selective querying.


3. Monitor Resource Usage

Docker can stream real-time metrics—CPU, memory, network I/O, block I/O—across all running containers:

docker container stats

Sample output:

CONTAINER ID   NAME           CPU %     MEM USAGE / LIMIT   MEM %   NET I/O        BLOCK I/O
59aa5eacd88c   webapp         50.00%    400KiB / 989.4MiB   0.04%   656B / 0B      0B / 0B

Note

The stats command runs continuously. Press <kbd>Ctrl+C</kbd> to stop the stream.


4. List Processes Inside a Container

Identify which processes are consuming resources within a specific container:

docker container top webapp

Example:

UID     PID    PPID  C STIME TTY TIME     CMD
root    17001  16985 0 13:23 ?   00:00:00 stress

This shows the stress process (host PID 17001) running inside webapp.


5. Fetch and Stream Container Logs

To retrieve application logs:

docker container logs <container_name_or_ID>

Follow logs in real time with:

docker container logs -f <container_name_or_ID>

Warning

If your logs are large, consider limiting output with options like --since or --tail to avoid overwhelming your terminal.


6. Stream Docker Events

Docker records events for containers, networks, volumes, and more. To see recent events—for example, within the last hour—run:

docker system events --since 60m

Sample output:

2020-01-14T18:30:30Z network connect ... (container=68649c8b..., name=bridge)
2020-01-14T18:30:30Z container start ... (image=ubuntu, name=casethree)

All resource lifecycle events can be retrieved using docker system events.


Summary of Inspection Commands

CommandPurpose
docker container lsList active containers
docker container inspect <id>Show detailed JSON metadata
docker container statsStream live resource usage
docker container top <name>List processes inside the container
docker container logs <id>Retrieve container logs
docker container logs -f <id>Follow logs in real time
docker system events --since 60mStream Docker engine events from last hour

Watch Video

Watch video content

Previous
Interacting with a Running Container