获取容器的 CONTAINER ID
docker ps -q
5354ce7e85e1
通过 docker top 获取 PID
docker top 5354ce7e85e1
UID PID PPID C STIME TTY TIME CMD
root 81534 81517 3 2019 ? 05:33:29 java -Djava.security.egd=file:/dev/./urandom -DLog4jContextSelector=org.apache.logging.log4j.core.async.AsyncLoggerContextSelector -Dspring.profiles.active=docker -jar /app.jar
获取所有容器的 PID
for l in `docker ps -q`;do docker top $l|awk -v dn="$l" 'NR>1 {print dn " PID is " $2}';done