Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker: different PID for `top` and `ps`

Tags:

linux

docker

I don't understand the difference in

$> docker top lamp-test
PID                 USER                COMMAND
31263               root                {supervisord} /usr/bin/python   /usr/bin/supervisord -n
31696               root                {mysqld_safe} /bin/sh /usr/bin/mysqld_safe
31697               root                apache2 -D FOREGROUND
...

and

$> docker exec lamp-test ps
PID TTY          TIME CMD
  1 ?        00:00:00 supervisord
433 ?        00:00:00 mysqld_safe
434 ?        00:00:00 apache2
831 ?        00:00:00 ps

So, the question is, why are the PID different ? I would say that the output from ps is namespaced, but if that is true, what is top showing!

like image 641
Jeanluca Scaljeri Avatar asked Nov 20 '15 20:11

Jeanluca Scaljeri


1 Answers

docker exec lamp-test ps show pids inside docker container.

docker top lamp-test show host system pids.

You can see a container processes, but You cannot kill them. This "flawed" isolation actually has some great benefits, like the ability to monitor the processes running inside all your containers from a single monitor process running on the host machine.

like image 156
Tomasz Jakub Rup Avatar answered Sep 22 '22 12:09

Tomasz Jakub Rup