当前位置:首页>编程日记>正文

docker inspect 获取 容器 镜像 元数据 简介

本站寻求有缘人接手,详细了解请联系站长QQ1493399855

目录

作用

语法格式

实际例子

获取容器 IP

获取容器 MAC 地址

获取容器日志路径

获取容器的元数据

获取镜像的元数据


作用

获取容器/镜像的元数据(JSON格式)


语法格式

docker inspect [OPTIONS] NAME|ID [NAME|ID...]

options 说明

option说明
-f指定返回值的模板文件
-s如果类型为容器,则显示文件总大小
--type返回指定类型的JSON


实际例子


获取容器 IP

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONTAINER_ID

docker inspect 获取 容器 镜像 元数据 简介 配图01

简单版本

docker inspect tomcat7 | grep IPAddress

docker inspect 获取 容器 镜像 元数据 简介 配图02

就是内容会多了点,但有输出关键信息就行


获取容器 MAC 地址

docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' $CONTAINER_ID

docker inspect 获取 容器 镜像 元数据 简介 配图03

docker inspect tomcat7 | grep MacAddress

docker inspect 获取 容器 镜像 元数据 简介 配图04

万物皆可 grep 


获取容器日志路径

docker inspect --format='{{.LogPath}}' $CONTAINER_ID

docker inspect 获取 容器 镜像 元数据 简介 配图05


获取容器的元数据

docker inspect tomcat7

 结果

[{"Id": "453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee","Created": "2020-11-16T15:04:21.46225831Z","Path": "catalina.sh","Args": ["run"],"State": {"Status": "running","Running": true,"Paused": false,"Restarting": false,"OOMKilled": false,"Dead": false,"Pid": 8151,"ExitCode": 0,"Error": "","StartedAt": "2020-11-16T16:52:39.762574155Z","FinishedAt": "2020-11-16T16:32:59.955468647Z"},"Image": "sha256:d0f27b446f0a9cf5638da4c45bfdb9a6e0abb5b5f2b168a59c1242ec31934b39","ResolvConfPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/resolv.conf","HostnamePath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/hostname","HostsPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/hosts","LogPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee-json.log","Name": "/tomcat7","RestartCount": 0,"Driver": "overlay2","Platform": "linux","MountLabel": "","ProcessLabel": "","AppArmorProfile": "","ExecIDs": null,"HostConfig": {"Binds": ["/usr/local/tomcat/webapps:/usr/local/tomcat/webapps"],"ContainerIDFile": "","LogConfig": {"Type": "json-file","Config": {}},"NetworkMode": "default","PortBindings": {"8080/tcp": [{"HostIp": "","HostPort": "9999"}]},"RestartPolicy": {"Name": "no","MaximumRetryCount": 0},"AutoRemove": false,"VolumeDriver": "","VolumesFrom": null,"CapAdd": null,"CapDrop": null,"Capabilities": null,"Dns": [],"DnsOptions": [],"DnsSearch": [],"ExtraHosts": null,"GroupAdd": null,"IpcMode": "private","Cgroup": "","Links": null,"OomScoreAdj": 0,"PidMode": "","Privileged": false,"PublishAllPorts": false,"ReadonlyRootfs": false,"SecurityOpt": null,"UTSMode": "","UsernsMode": "","ShmSize": 67108864,"Runtime": "runc","ConsoleSize": [0,0],"Isolation": "","CpuShares": 0,"Memory": 0,"NanoCpus": 0,"CgroupParent": "","BlkioWeight": 0,"BlkioWeightDevice": [],"BlkioDeviceReadBps": null,"BlkioDeviceWriteBps": null,"BlkioDeviceReadIOps": null,"BlkioDeviceWriteIOps": null,"CpuPeriod": 0,"CpuQuota": 0,"CpuRealtimePeriod": 0,"CpuRealtimeRuntime": 0,"CpusetCpus": "","CpusetMems": "","Devices": [],"DeviceCgroupRules": null,"DeviceRequests": null,"KernelMemory": 0,"KernelMemoryTCP": 0,"MemoryReservation": 0,"MemorySwap": 0,"MemorySwappiness": null,"OomKillDisable": false,"PidsLimit": null,"Ulimits": null,"CpuCount": 0,"CpuPercent": 0,"IOMaximumIOps": 0,"IOMaximumBandwidth": 0,"MaskedPaths": ["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths": ["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410-init/diff:/var/lib/docker/overlay2/42ba885fce62f2962b45c326cce2c29b1fd8e114fe549df69fef65b37ab230fa/diff:/var/lib/docker/overlay2/b94481ba0b495bb249e06173dee0e218c13f3e65f7fe23fd5b782c79bd30fe4e/diff:/var/lib/docker/overlay2/177d76f6dd0dca23e1ec9befe03326cbe23fa21a3efa4cfaa74c7f8792198a06/diff:/var/lib/docker/overlay2/651d96c0ee26ee6a5b4206eb812d0c5ba698f1deddfb97f7b943b1a6593b0528/diff:/var/lib/docker/overlay2/5a61caef4107e0883a82e23984c68b00e81c0ce59b603b75cfd9f6a21ca14a18/diff:/var/lib/docker/overlay2/e2dc6737c4504743ab26d2a8e25bae2eaf698493d61d1aff2b723cbff152af81/diff:/var/lib/docker/overlay2/fdca5f4d98e7a1c7a4e3ec17f64b311872fe3cbed6714b819631fea68834b5b8/diff:/var/lib/docker/overlay2/c235b69a918380eccb2202487e8b1581f8af7396ff23bf29bf512e049a10b251/diff:/var/lib/docker/overlay2/6dc73398e20a27e7aa90545d1098152f6e817c5e9cdf79a8c1b647aa86a51e0c/diff:/var/lib/docker/overlay2/140b83aec0bf703150319d5d27ba7192a3f3496486a1baac37809c656d802733/diff","MergedDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/merged","UpperDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/diff","WorkDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/work"},"Name": "overlay2"},"Mounts": [{"Type": "bind","Source": "/usr/local/tomcat/webapps","Destination": "/usr/local/tomcat/webapps","Mode": "","RW": true,"Propagation": "rprivate"}],"Config": {"Hostname": "453d5e858560","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"ExposedPorts": {"8080/tcp": {}},"Tty": false,"OpenStdin": true,"StdinOnce": false,"Env": ["PATH=/usr/local/tomcat/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/local/openjdk-8","JAVA_VERSION=8u265","CATALINA_HOME=/usr/local/tomcat","TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib","LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib","GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23","TOMCAT_MAJOR=7","TOMCAT_VERSION=7.0.106","TOMCAT_SHA512=f1fb2f3db9e66e66df120b058c216e72ec30df90abd80feda49773fa35c3c00cb56e4d264803696e1a71591d5cb60fcabf60f37e1774d549642ebe3eb902622d"],"Cmd": ["catalina.sh","run"],"Image": "tomcat:7","Volumes": null,"WorkingDir": "/usr/local/tomcat","Entrypoint": null,"OnBuild": null,"Labels": {}},"NetworkSettings": {"Bridge": "","SandboxID": "42de54c029f2455fb86407ac397fa491a01819106c267c2ae8ca84c8f7955686","HairpinMode": false,"LinkLocalIPv6Address": "","LinkLocalIPv6PrefixLen": 0,"Ports": {"8080/tcp": [{"HostIp": "0.0.0.0","HostPort": "9999"}]},"SandboxKey": "/var/run/docker/netns/42de54c029f2","SecondaryIPAddresses": null,"SecondaryIPv6Addresses": null,"EndpointID": "86302746bf794210a2d24b869c6a1175586124de8b3128c98e33150411f213c1","Gateway": "172.17.0.1","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"IPAddress": "172.17.0.3","IPPrefixLen": 16,"IPv6Gateway": "","MacAddress": "02:42:ac:11:00:03","Networks": {"bridge": {"IPAMConfig": null,"Links": null,"Aliases": null,"NetworkID": "b6f97cbdc0ef2e334507c79e4e5aa99703e6bfc6735b199fc34e47d3725de3ee","EndpointID": "86302746bf794210a2d24b869c6a1175586124de8b3128c98e33150411f213c1","Gateway": "172.17.0.1","IPAddress": "172.17.0.3","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"MacAddress": "02:42:ac:11:00:03","DriverOpts": null}}}}
]


获取镜像的元数据

docker inspect tomcat:7

结果

[{"Id": "453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee","Created": "2020-11-16T15:04:21.46225831Z","Path": "catalina.sh","Args": ["run"],"State": {"Status": "running","Running": true,"Paused": false,"Restarting": false,"OOMKilled": false,"Dead": false,"Pid": 8151,"ExitCode": 0,"Error": "","StartedAt": "2020-11-16T16:52:39.762574155Z","FinishedAt": "2020-11-16T16:32:59.955468647Z"},"Image": "sha256:d0f27b446f0a9cf5638da4c45bfdb9a6e0abb5b5f2b168a59c1242ec31934b39","ResolvConfPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/resolv.conf","HostnamePath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/hostname","HostsPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/hosts","LogPath": "/var/lib/docker/containers/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee/453d5e85856052a33f25954ea491648d4f465b073a0b13257734271534ce25ee-json.log","Name": "/tomcat7","RestartCount": 0,"Driver": "overlay2","Platform": "linux","MountLabel": "","ProcessLabel": "","AppArmorProfile": "","ExecIDs": null,"HostConfig": {"Binds": ["/usr/local/tomcat/webapps:/usr/local/tomcat/webapps"],"ContainerIDFile": "","LogConfig": {"Type": "json-file","Config": {}},"NetworkMode": "default","PortBindings": {"8080/tcp": [{"HostIp": "","HostPort": "9999"}]},"RestartPolicy": {"Name": "no","MaximumRetryCount": 0},"AutoRemove": false,"VolumeDriver": "","VolumesFrom": null,"CapAdd": null,"CapDrop": null,"Capabilities": null,"Dns": [],"DnsOptions": [],"DnsSearch": [],"ExtraHosts": null,"GroupAdd": null,"IpcMode": "private","Cgroup": "","Links": null,"OomScoreAdj": 0,"PidMode": "","Privileged": false,"PublishAllPorts": false,"ReadonlyRootfs": false,"SecurityOpt": null,"UTSMode": "","UsernsMode": "","ShmSize": 67108864,"Runtime": "runc","ConsoleSize": [0,0],"Isolation": "","CpuShares": 0,"Memory": 0,"NanoCpus": 0,"CgroupParent": "","BlkioWeight": 0,"BlkioWeightDevice": [],"BlkioDeviceReadBps": null,"BlkioDeviceWriteBps": null,"BlkioDeviceReadIOps": null,"BlkioDeviceWriteIOps": null,"CpuPeriod": 0,"CpuQuota": 0,"CpuRealtimePeriod": 0,"CpuRealtimeRuntime": 0,"CpusetCpus": "","CpusetMems": "","Devices": [],"DeviceCgroupRules": null,"DeviceRequests": null,"KernelMemory": 0,"KernelMemoryTCP": 0,"MemoryReservation": 0,"MemorySwap": 0,"MemorySwappiness": null,"OomKillDisable": false,"PidsLimit": null,"Ulimits": null,"CpuCount": 0,"CpuPercent": 0,"IOMaximumIOps": 0,"IOMaximumBandwidth": 0,"MaskedPaths": ["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths": ["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410-init/diff:/var/lib/docker/overlay2/42ba885fce62f2962b45c326cce2c29b1fd8e114fe549df69fef65b37ab230fa/diff:/var/lib/docker/overlay2/b94481ba0b495bb249e06173dee0e218c13f3e65f7fe23fd5b782c79bd30fe4e/diff:/var/lib/docker/overlay2/177d76f6dd0dca23e1ec9befe03326cbe23fa21a3efa4cfaa74c7f8792198a06/diff:/var/lib/docker/overlay2/651d96c0ee26ee6a5b4206eb812d0c5ba698f1deddfb97f7b943b1a6593b0528/diff:/var/lib/docker/overlay2/5a61caef4107e0883a82e23984c68b00e81c0ce59b603b75cfd9f6a21ca14a18/diff:/var/lib/docker/overlay2/e2dc6737c4504743ab26d2a8e25bae2eaf698493d61d1aff2b723cbff152af81/diff:/var/lib/docker/overlay2/fdca5f4d98e7a1c7a4e3ec17f64b311872fe3cbed6714b819631fea68834b5b8/diff:/var/lib/docker/overlay2/c235b69a918380eccb2202487e8b1581f8af7396ff23bf29bf512e049a10b251/diff:/var/lib/docker/overlay2/6dc73398e20a27e7aa90545d1098152f6e817c5e9cdf79a8c1b647aa86a51e0c/diff:/var/lib/docker/overlay2/140b83aec0bf703150319d5d27ba7192a3f3496486a1baac37809c656d802733/diff","MergedDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/merged","UpperDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/diff","WorkDir": "/var/lib/docker/overlay2/f55d301001836d0bca303385ecf6981356823dab220a0f05cbf4101d0c4b6410/work"},"Name": "overlay2"},"Mounts": [{"Type": "bind","Source": "/usr/local/tomcat/webapps","Destination": "/usr/local/tomcat/webapps","Mode": "","RW": true,"Propagation": "rprivate"}],"Config": {"Hostname": "453d5e858560","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"ExposedPorts": {"8080/tcp": {}},"Tty": false,"OpenStdin": true,"StdinOnce": false,"Env": ["PATH=/usr/local/tomcat/bin:/usr/local/openjdk-8/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","LANG=C.UTF-8","JAVA_HOME=/usr/local/openjdk-8","JAVA_VERSION=8u265","CATALINA_HOME=/usr/local/tomcat","TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib","LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib","GPG_KEYS=05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5 541FBE7D8F78B25E055DDEE13C370389288584E7 61B832AC2F1C5A90F0F9B00A1C506407564C17A3 713DA88BE50911535FE716F5208B0AB1D63011C7 79F7026C690BAA50B92CD8B66A3AD3F4F22C4FED 9BA44C2621385CB966EBA586F72C284D731FABEE A27677289986DB50844682F8ACB77FC2E86E29AC A9C5DF4D22E99998D9875A5110C01C5A2F6059E7 DCFD35E0BF8CA7344752DE8B6FB21E8933C60243 F3A04C595DB5B6A5F1ECA43E3B7BBB100D811BBE F7DA48BB64BCB84ECBA7EE6935CD23C10D498E23","TOMCAT_MAJOR=7","TOMCAT_VERSION=7.0.106","TOMCAT_SHA512=f1fb2f3db9e66e66df120b058c216e72ec30df90abd80feda49773fa35c3c00cb56e4d264803696e1a71591d5cb60fcabf60f37e1774d549642ebe3eb902622d"],"Cmd": ["catalina.sh","run"],"Image": "tomcat:7","Volumes": null,"WorkingDir": "/usr/local/tomcat","Entrypoint": null,"OnBuild": null,"Labels": {}},"NetworkSettings": {"Bridge": "","SandboxID": "42de54c029f2455fb86407ac397fa491a01819106c267c2ae8ca84c8f7955686","HairpinMode": false,"LinkLocalIPv6Address": "","LinkLocalIPv6PrefixLen": 0,"Ports": {"8080/tcp": [{"HostIp": "0.0.0.0","HostPort": "9999"}]},"SandboxKey": "/var/run/docker/netns/42de54c029f2","SecondaryIPAddresses": null,"SecondaryIPv6Addresses": null,"EndpointID": "86302746bf794210a2d24b869c6a1175586124de8b3128c98e33150411f213c1","Gateway": "172.17.0.1","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"IPAddress": "172.17.0.3","IPPrefixLen": 16,"IPv6Gateway": "","MacAddress": "02:42:ac:11:00:03","Networks": {"bridge": {"IPAMConfig": null,"Links": null,"Aliases": null,"NetworkID": "b6f97cbdc0ef2e334507c79e4e5aa99703e6bfc6735b199fc34e47d3725de3ee","EndpointID": "86302746bf794210a2d24b869c6a1175586124de8b3128c98e33150411f213c1","Gateway": "172.17.0.1","IPAddress": "172.17.0.3","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"MacAddress": "02:42:ac:11:00:03","DriverOpts": null}}}}
]


http://www.coolblog.cn/news/1f92b120d91e3d16.html

相关文章:

  • asp多表查询并显示_SpringBoot系列(五):SpringBoot整合Mybatis实现多表关联查询
  • s7day2学习记录
  • 【求锤得锤的故事】Redis锁从面试连环炮聊到神仙打架。
  • 矿Spring入门Demo
  • 拼音怎么写_老师:不会写的字用圈代替,看到孩子试卷,网友:人才
  • Linux 实时流量监测(iptraf中文图解)
  • Win10 + Python + GPU版MXNet + VS2015 + RTools + R配置
  • 美颜
  • shell访问php文件夹,Shell获取某目录下所有文件夹的名称
  • 如何优雅的实现 Spring Boot 接口参数加密解密?
  • LeCun亲授的深度学习入门课:从飞行器的发明到卷积神经网络
  • 法拉利虚拟学院2010 服务器,法拉利虚拟学院2010
  • Mac原生Terminal快速登录ssh
  • 支撑微博千亿调用的轻量级RPC框架:Motan
  • mysql commit 机制_1024MySQL事物提交机制
  • java受保护的数据与_Javascript类定义语法,私有成员、受保护成员、静态成员等介绍...
  • 2019-9
  • jquery 使用小技巧
  • 科学计算工具NumPy(3):ndarray的元素处理
  • vscode pylint 错误_将实际未错误的py库添加到pylint白名单
  • 工程师在工作电脑存 64G 不雅文件,被公司开除后索赔 41 万,结果…
  • linux批量创建用户和密码
  • js常用阻止冒泡事件
  • 气泡图在开源监控工具中的应用效果
  • newinsets用法java_Java XYPlot.setInsets方法代碼示例
  • 各类型土地利用图例_划重点!国土空间总体规划——土地利用
  • php 启动服务器监听
  • dubbo简单示例
  • Ubuntu13.10:[3]如何开启SSH SERVER服务
  • [iptables]Redhat 7.2下使用iptables实现NAT
  • Django View(视图系统)
  • 【设计模式】 模式PK:策略模式VS状态模式
  • JS实现-页面数据无限加载
  • CSS小技巧——CSS滚动条美化
  • 最新DOS大全
  • 阿里巴巴分布式服务框架 Dubbo
  • 阿里大鱼.net core 发送短信
  • Sorenson Capital:值得投资的 5 种 AI 技术
  • 程序员入错行怎么办?
  • Arm芯片的新革命在缓缓上演
  • 两张超级大表join优化
  • 第九天函数
  • Linux软件安装-----apache安装
  • HDU 5988 最小费用流
  • 通过Spark进行ALS离线和Stream实时推荐
  • 《看透springmvc源码分析与实践》读书笔记一
  • nagios自写插件—check_file
  • python3 错误 Max retries exceeded with url 解决方法
  • 正式开课!如何学习相机模型与标定?(单目+双目+鱼眼+深度相机)
  • 行为模式之Template Method模式