Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding Docker container processes? (from host point of view)

I am doing some tests on docker and containers and I was wondering:

Is there a method I can use to find all process associated with a docker container by its name or ID from the host point of view.

After all, at the end of the day a container is a set of virtualized processes.

like image 485
Walid Hanafy Avatar asked Jan 19 '16 14:01

Walid Hanafy


People also ask

Can we check the container process on Docker host?

You can use docker top command. This command lists all processes running within your container. All methods mentioned by others are also possible to use but this one should be easiest.

How do I see what processes are running in a Docker container?

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

Can you see the processes running inside a container from the outside?

Yes this is normal. LXC containers are not virtualisation of hardware, and so there is a single kernel that is running all of the processes.


1 Answers

You can use docker top command. This command lists all processes running within your container.

For instance this command on a single process container on my box displays:

UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD root                14097               13930               0                   23:17               pts/6               00:00:00            /bin/bash 

All methods mentioned by others are also possible to use but this one should be easiest.

Update:

To simply get the main process id within the container use this command:

 docker inspect -f '{{.State.Pid}}' <container id> 
like image 123
Boynux Avatar answered Oct 17 '22 07:10

Boynux