在docker宿主机上查找指定容器内运行的所有进程的PID
找到指定容器的所有进程的PID可以更方便的对容器进程进行管理,特别是在某些容器卡住无法连接的场景。
1、找出容器ID
# docker ps
2、进入相应目录
# cd /sys/fs/cgroup/memory/docker/d14e1a6182eeed7c8f2a7c0a315a790a16bfbab1fdc7a73813cdeee494e8050a/
3、进程号就存在一个文件里面
# cat cgroup.procs
1761
1869
1877
1892
1900
1903
3512
4793
4794
4、查看所有进程,找出对应的进程树分支
# ps auxwwf
...
root 1761 0.0 0.0 11360 2432 pts/13 Ss 06:40 0:00 \_ /bin/bash /root/bin/autoboot.sh
root 1869 0.0 0.0 66744 2772 ? Ss 06:40 0:00 \_ /usr/sbin/sshd
497 1877 0.0 0.0 41396 2732 ? Ss 06:40 0:00 \_ /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
root 1892 50.9 1.0 19031092 1068868 pts/13 Sl 06:40 143:06 \_ /usr/local/jdk/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -server -Xms2048m -Xmx2048m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=/var/log/jvm/tomcat.dump -Xloggc:/var/log/jvm/tomcat_real.log -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCDateStamps -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.endorsed.dirs=/usr/local/tomcat/endorsed -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 1900 0.0 0.0 20508 2304 ? Ss 06:40 0:00 \_ crond
root 1903 0.0 0.0 11492 2688 pts/13 S+ 06:40 0:00 \_ /bin/bash
root 3512 13.5 3.9 3922968 3892780 ? Ssl 06:46 37:15 \_ /usr/local/bin/redis-server *:6380
root 4793 0.0