How to See Container Processes in Docker
To see processes running inside a Docker container, use the
docker top <container_name_or_id> command which lists active processes. Alternatively, you can run docker exec <container> ps aux to execute process listing inside the container.Syntax
The main command to view container processes is docker top. It shows the processes running inside a container.
docker top <container_name_or_id>: Lists active processes inside the specified container.docker exec <container> ps aux: Runs theps auxcommand inside the container to show detailed process info.
bash
docker top <container_name_or_id> docker exec <container_name_or_id> ps aux
Example
This example shows how to list processes inside a running container named myapp. First, docker top lists the processes. Then, docker exec runs ps aux inside the container for detailed info.
bash
docker top myapp docker exec myapp ps aux
Output
UID PID PPID C STIME TTY TIME CMD
root 1234 1 0 10:00 ? 00:00:00 /bin/sh -c myapp
root 1250 1234 0 10:00 ? 00:00:01 /usr/bin/myapp
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1234 0.0 0.1 18540 3200 ? Ss 10:00 0:00 /bin/sh -c myapp
root 1250 0.1 0.5 50000 12000 ? Sl 10:00 0:01 /usr/bin/myapp
Common Pitfalls
Common mistakes when viewing container processes include:
- Using
docker topwithout specifying the correct container name or ID causes an error. - Expecting
docker topoutput to be identical to hostpsoutput; it may differ by Docker version and platform. - Not having the container running will cause commands to fail.
- Using
docker execrequires the container to have thepscommand installed; some minimal images may lack it.
Wrong: docker top wrong_container (container does not exist)
Right: docker top myapp (correct container name)
bash
docker top wrong_container
# Error: No such container: wrong_container
docker top myapp
# Lists processes inside 'myapp' containerQuick Reference
Summary of commands to see container processes:
| Command | Description |
|---|---|
| docker top | Show active processes inside the container |
| docker exec | Run detailed process list inside the container |
| docker ps | List running containers to get container names or IDs |
Key Takeaways
Use
docker top <container> to quickly see running processes inside a container.If you need detailed process info, run
docker exec <container> ps aux.Make sure the container is running and you use the correct container name or ID.
Some minimal containers may not have
ps installed, so docker exec might fail.Use
docker ps to find container names or IDs before checking processes.