0
0
DockerHow-ToBeginner · 3 min read

How to Use Docker Top Command to View Container Processes

Use the docker top <container> command to list the processes running inside a Docker container. This shows details like process IDs and commands, helping you monitor container activity.
📐

Syntax

The basic syntax of the docker top command is:

  • docker top <container> [ps OPTIONS]

Here, <container> is the container name or ID. You can optionally add ps options to customize the process list output.

bash
docker top <container> [ps OPTIONS]
💻

Example

This example shows how to use docker top to view processes inside a running container named mycontainer. It lists the process IDs, user, and commands running inside.

bash
docker run -d --name mycontainer nginx

docker top mycontainer
Output
UID PID PPID C STIME TTY TIME CMD root 12345 12330 0 10:00 ? 00:00:00 nginx: master process nginx -g daemon off; www-data 12346 12345 0 10:00 ? 00:00:00 nginx: worker process
⚠️

Common Pitfalls

Common mistakes when using docker top include:

  • Using the container name or ID incorrectly. Always verify the container is running with docker ps.
  • Expecting docker top to show host processes. It only shows processes inside the container.
  • Not using the correct ps options for detailed output. You can add options like aux for more info.
bash
docker top wrongcontainer
# Error: No such container: wrongcontainer

docker top mycontainer aux
# Correct usage with ps options
📊

Quick Reference

OptionDescription
<container>Name or ID of the container to inspect
ps OPTIONSOptional Linux ps command options to customize output
No optionsShows default process list with PID, user, and command
Use docker psCheck running containers before using docker top

Key Takeaways

Use docker top <container> to see running processes inside a container.
Verify the container is running with docker ps before using docker top.
Add ps options to customize the process list output if needed.
The command only shows container processes, not host system processes.
Use container name or ID correctly to avoid errors.