根据进程id pid 查容器id

Posted fsckzy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了根据进程id pid 查容器id相关的知识,希望对你有一定的参考价值。

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的主要内容,如果未能解决你的问题,请参考以下文章

Docker 数据库容器正在运行。另一个带有 pid <id> 的进程正在使用 unix 套接字文件

Linux为啥查某个进程的线程,查出来的所有线程的pid不一样啊

通过Docker进程pid获取容器id

linux怎么查询进程和进程的id

进程ID中有字母如何换算成十进制PID

安卓如何查看进程信息,都说是用ps看到pid后根据pid去/proc/pid/maps中去看调用的