码迷,mamicode.com
首页 > 系统相关 > 详细

根据进程id pid 查容器id

时间:2019-11-13 16:11:51      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:容器   system   proc   free   hmm   scope   sed   you   cgroup   

To get container ID you can use:

cat /proc/<process-pid>/cgroup

Then to convert the container ID to docker container name:

docker inspect --format '{{.Name}}' "${containerId}" | sed 's/^\///'

以下是例子

[root@nodejs1 ~]# cat /proc/68069/cgroup 
11:pids:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
10:hugetlb:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
9:perf_event:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
8:devices:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
7:freezer:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
6:net_prio,net_cls:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
5:cpuacct,cpu:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
4:cpuset:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
3:blkio:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
2:memory:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
1:name=systemd:/system.slice/docker-f66fdd05b0780e9914a32ab3594259a66a49d7f18c7eca9f4d60d93d63bdf2d7.scope
[root@nodejs1 ~]# docker inspect --format '{{.Name}}' "f66f" | sed 's/^\///'
shebao.1.hx50qn3yaahmm03nybc1fwcyr

根据进程id pid 查容器id

标签:容器   system   proc   free   hmm   scope   sed   you   cgroup   

原文地址:https://www.cnblogs.com/fsckzy/p/11849882.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!