在主機中,有沒有辦法獲取ps特定的容器?
如果具有 cgroup foo 的容器具有行程 bar, baz, bam 那么 likeps --cgroup-id foo應該列印psas if 在容器(cgroup)中的結果,如下所示:
PID USER TIME COMMAND
1 root 0:00 bar
60 root 0:00 baz
206 root 0:00 bam
不過不一定是ps這樣,我希望它可以由一兩個命令組成。
謝謝!
uj5u.com熱心網友回復:
有一個docker top命令,例如:
$ 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
或者,如果容器附帶ps:
docker exec $container_name ps
如果ps不包含在容器中,您可以在同一個 pid 命名空間中運行不同的容器:
$ 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
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/312805.html
上一篇:為什么我的自定義Dockerfile不能通過docker-compose網路連接,而其他服務可以連接?
下一篇:運行可執行檔案并同時讀取日志
