一个伪linux粉丝的blog

  1. 首页
  2. unix/linux
  3. 正文

How to check container id through dm disk path

5 8 月, 2021 728点热度 0人点赞 0条评论

1. 背景

最近遇到几个客户咨询如何通过dm盘挂载路径,来反查对应的容器名称,截图是立即给出去了,自己博客也补录一下。

2. 步骤

2.1. 需要查询的 dm 盘

df -h
得到如下输出结果,我们取最后一条路径 dm-21来说明一下。

2.2. 得到红框中的字符串

如下: a0525c135bf1bf9038ab355c398f7d1e4fcf961072a24b2e235007d4748015e6

2.3. 循环查询脚本
通过下面的查询脚本来查询字符串的输出
docker ps -a -q | xargs docker inspect | jq '.[] | select(.GraphDriver.Data.DeviceName | contains("a0525c135bf1bf9038ab355c398f7d1e4fcf961072a24b2e235007d4748015e6")) | .Id'

2.3.1. 得到 id

0b3fd4807c03

2.3.2. 得到对应容器

docker ps |grep 0b3fd4807c03

k8s_dcei-uf-installer_dcei-uf-installer-qczj7_kube-system_2c95991b-d57f-11eb-a046-0242ac120004_0

docker inspect 0b3fd4807c03

得到更多信息

或者 docker exec -it k8s_dcei-uf-installer_dcei-uf-installer-qczj7_kube-system_2c95991b-d57f-11eb-a046-0242ac120004_0 sh 进入容器等等工作。。。。

overlay2补充说明

补充一下,如果是overlay2 这种存储驱动后,查询字段需要变动了。你会发现路径后面多了一层merged结构。

对应的层级结构不再是.GraphDriver.Data.DeviceName

而是 .GraphDriver.Data.MergedDir

因此查询命令调整如下

docker ps -a -q | xargs docker inspect | jq '.[] | select(.GraphDriver.Data.MergedDir | contains("b468b64039036dcd18abee3a376689f1826d340f69d41fc01efc749b05ea77ab")) | .Id'

 

补充一种循环查询方法
aa="2b66";for i in docker ps -q;do docker inspect $i|grep $aa >/dev/null && echo $i;done

可惜 overlay2后,sar 记录已经不显示具体容器了。

相关文章:

  1. LAMP 系统性能调优,第 2 部分: 优化 Apache 和 PHP
  2. plowshare -- command-line application to download files for file-sharing websites
  3. Moving WordPress blog to a new server
  4. download files from qiniu
标签: 暂无
最后更新:28 6 月, 2022

wanjie

这个人很懒,什么都没留下

点赞
< 上一篇
下一篇 >

文章评论

razz evil exclaim smile redface biggrin eek confused idea lol mad twisted rolleyes wink cool arrow neutral cry mrgreen drooling persevering
取消回复

This site uses Akismet to reduce spam. Learn how your comment data is processed.

归档
分类
  • network / 332篇
  • Uncategorized / 116篇
  • unix/linux / 121篇
  • 业界资讯 / 38篇
  • 公司杂事 / 11篇
  • 数码影像 / 12篇
  • 美剧 / 3篇
  • 美图共赏 / 21篇
  • 英语学习 / 3篇
标签聚合
Nginx 浏览器 k8s squid nexus debian 泰国 kernel jira ldap openssl gitlab postgres dreamhost wget 网站运营 kubectl Google google-chrome 虚拟主机 天翼live d90 docker Google Voice VPS Ubuntu 邮件归档 deepseek dreamhost空间 ssh

COPYRIGHT © 2008-2025 wanjie.info. ALL RIGHTS RESERVED.

Theme Kratos Made By Seaton Jiang