Always_Beginner
Always_Beginner

Reputation: 2886

How to log all the processes running inside a Docker container?

After having logged into the container using the command -

docker exec -it <container_name>

How do I check for all the processes running inside the container? Is "ps aux" the correct way to do it? Are there any better alternatives/approaches?

Upvotes: 37

Views: 77896

Answers (3)

Rao
Rao

Reputation: 21359

It is possible to show all the processes running inside a container without login to terminal by using the following command. Of course, it is just like how one can see by using ps -eaf, so just add it to docker exec.

bash $ docker exec -it test1 ps -eaf
PID   USER     TIME   COMMAND
    1 root       0:00 sh
    7 root       0:00 sh
   60 root       0:00 /bin/sh
   67 root       0:00 /bin/sh
   84 root       0:00 ps -eaf

Like it was mentioned, if you are already inside of a container, then just use ps -eaf command to see the running processes.

By the way, it is recommended to have one user application / process per container.

Upvotes: 25

sais
sais

Reputation: 843

Extending from the answer of @Slawomir

And With ps option, docker top [--help] CONTAINER [ps OPTIONS]

docker top <container_id> -eo pid,cmd

Upvotes: 17

Slawomir Jaranowski
Slawomir Jaranowski

Reputation: 8497

You can use dedicated command top to list process in docker container, regardless of the operating system in container.

docker top <container>

Upvotes: 64

Related Questions