简体   繁体   中英

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 ps doesn't seem to display that information.

一种可能的方法是:

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM