Top Command
While docker stats shows resource usage for entire containers, the docker top command shows the individual running processes inside a container.
docker top CONTAINER [ps OPTIONS]
Key Difference:
- Use
statsto monitor whole containers. - Use
topto inspect the processes running within a specific container.
Inspecting Container Processes
If you have the cpu-stress and mem-stress containers running from the previous lesson, you can compare them:
-
Check the processes in the CPU-intensive container:
docker top cpu-stress -
Check the processes in the memory-intensive container:
docker top mem-stress
You should notice that the CPU-intensive container has multiple processes with high CPU usage (under the “C” column or similar process stats), while the memory-intensive container has fewer processes but consumes a lot of RAM.
(Don’t forget to stop and remove these test containers when you are done!)