Docker

How do I List Processes Running in a Docker Container?

Docker is a forum that is designed to help users build, deploy, and manage applications inside the containers. Docker containers are lightweight, independent executable packages that provide separate environments for applications to run. One of the most essential features of Docker is managing and monitoring the processes running inside the containers.

In this write-up, we will talk about showing processes running in a Docker container.

How do I list Processes Running in a Docker Container?

Different commands are used for listing the currently running processes in a container, such as:

Using “docker inspect”

To list the running process of Docker containers, first get the list of currently running containers by executing the below-provided command:

docker ps

According to the below-given output, thirsty_meitner container is running:

Now, run the docker inspect command to list the Docker container’s running processes:

docker inspect thirsty_meitner

Here, the comprehensive detail of the container along with its running processes has been listed successfully:

Using “docker top”

Another easiest way to display the processes running in Docker containers is by executing the docker top command. It shows processes in real-time and helps users diagnose as well as debug problems. As follows:

docker top thirsty_meitner

As you can see, the information about the running processes has been displayed along with their user ID (UID), process ID (PID), CPU usage, and many more:

Using “docker exec”

The docker exec command is also used for listing the running processes in a Docker container along with the ps command. Along with this command, you can use multiple arguments and options for more detail. For instance, use the provided command along with the -aux option for showing the running processes of a container as well as user ID, process ID, CPU usage, memory usage, the process starting time, command, and many more:

docker exec thirsty_meitner ps -aux

That’s all about listing processes running in a Docker Container.

Conclusion

Multiple commands are used for listing the processes running in Docker containers, such as the “docker inspect” command to display the comprehensive detail of the container and its running process, the “docker top” command, and the “docker exec” command for showing the running processes including the user ID, process ID, CPU usage, memory usage, the process starting time, and command. This guide illustrated the multiple commands for listing processes running in a Docker container.

About the author

Maria Naz

I hold a master's degree in computer science. I am passionate about my work, exploring new technologies, learning programming languages, and I love to share my knowledge with the world.