[英]Root PID of Docker container
How can I find the external PID of the root PID inside a Docker container - that is, the one that has PID 1 inside the container? 如何在Docker容器中找到根PID的外部PID - 也就是说,容器内有PID 1的那个?
docker ps
doesn't seem to display that information. docker ps
似乎没有显示该信息。
一种可能的方法是:
docker inspect -f '{{ .State.Pid }}' $CONTAINER_ID
请试试:
docker inspect -f '{{.State.Pid}}' $(docker ps -q)
Here is a POSIX shell function that captures the PID for a given container. 这是一个POSIX shell函数,它捕获给定容器的PID。
pid_for_container() {
ps -C lxc-start -o pid= -o args= | fgrep -- " -n $1" | cut -d' ' -f1
}
It is a minimal (I hope) pipeline for this purpose, using the cheapest possible ( fgrep
instead of grep
, cut
instead of awk
) commands. 它是用于此目的的最小(我希望)管道,使用最便宜的(
fgrep
而不是grep
, cut
而不是awk
)命令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.