in the host, is there any way to get ps
of specific container?
if a container having cgroup foo has processes bar, baz, bam
then like ps --cgroup-id foo
should print the result of ps
as if in the container(cgroup) as follows:
PID USER TIME COMMAND
1 root 0:00 bar
60 root 0:00 baz
206 root 0:00 bam
it doesn't have to be ps
though, I hope it could be made of just one or two commands.
Thanks!
CodePudding user response:
There's a docker top
command, e.g.:
$ docker top 9f2
UID PID PPID C STIME TTY TIME CMD
root 20659 20621 0 Oct08 ? 00:00:00 nginx: master process nginx -g daemon off;
systemd 20825 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20826 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20827 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20828 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20829 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20830 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20831 20659 0 Oct08 ? 00:00:00 nginx: worker process
systemd 20832 20659 0 Oct08 ? 00:00:00 nginx: worker process
Or you can exec into the container if the container ships with ps
:
docker exec $container_name ps
And if ps
isn't included in the container, you can run a different container in the same pid namespace:
$ docker run --pid container:9f2 busybox ps -ef
PID USER TIME COMMAND
1 root 0:00 nginx: master process nginx -g daemon off;
23 101 0:00 nginx: worker process
24 101 0:00 nginx: worker process
25 101 0:00 nginx: worker process
26 101 0:00 nginx: worker process
27 101 0:00 nginx: worker process
28 101 0:00 nginx: worker process
29 101 0:00 nginx: worker process
30 101 0:00 nginx: worker process
31 root 0:00 ps -ef