通过PID查找归属容器

用hexo进程为例

$ ps -ef | grep hexo
root     10775 10746  0 11:12 pts/1    00:00:01 hexo
  1. 定位父子进程
 pstree -p | grep 10775
           |-dockerd-current(11961)-+-docker-containe(11986)-+-docker-containe(10746)-+-hexo(10775)-+-{hexo}(10853)
  1. 定位docker进程
$ ps aux | grep 10746
root     10746  0.0  0.1 264752  2936 ?        Sl   11:12   0:00 /usr/bin/docker-containerd-shim-current 889a992e68205b1a585fccef8d56305827a2941b22b1ce4e9b2480268b29b344 /var/run/docker/libcontainerd/889a992e68205b1a585fccef8d56305827a2941b22b1ce4e9b2480268b29b344 /usr/libexec/docker/docker-runc-current
  1. 定位容器id

docker-containerd-shim-current 后的字符串为容器的全id,我可以直接复制前5个字符定位容器

docker ps -a | grep 889a9
889a992e6820        docker.io/ipple1986/hexo:latest   "hexo server"            22 minutes ago      Up 22 minutes               0.0.0.0:80->4000/tcp   competent_goldwasser

你可能感兴趣的:(通过PID查找归属容器)