当前位置:   article > 正文

Docker基础:容器元数据详解_docker inspect获取内容详解

docker inspect获取内容详解

目录

1、命令格式

2、用法介绍

2.1 查看IP地址

2.2 查看MAC地址

2.3 查看容器详细信息


今天给大家介绍Docker容器元数据里面包含内容详解,如有不当之处,欢迎大家指正。

查看容器元数据主要通过docker inspect 容器id进行查看。今天通过docker安装的mysql查看启动的容器。

1、命令格式

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

命令选项

名称

默认值

描述

--format , -f

格式化输出

--size , -s

显示的最大文件大小

--type

返回指定类型的 JSON

使用 inspect 命令可以查看一个容器的具体信息。

2、用法介绍

2.1 查看IP地址

docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' 572219d3a0ca

  1. [root@ecs-337444 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.MacAddress}}{{end}}' 572219d3a0ca
  2. 02:42:ac:11:00:03

2.2 查看MAC地址

docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 572219d3a0ca

  1. [root@ecs-337444 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' 572219d3a0ca
  2. 172.17.0.3

2.3 查看容器详细信息

docker inspect 572219d3a0ca

下面把能找到资料的参数解释给大家标注一下,大家有不同意见的欢迎留言我会及时更正。

  1. [
  2. {
  3. "Id": "572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84", #完整容器id
  4. "Created": "2022-06-08T08:29:58.542781937Z", #容器创建时间
  5. "Path": "docker-entrypoint.sh", #启动容器时,通过shell脚本执行些预处理逻辑中shell脚本的名称
  6. "Args": [
  7. "mysqld"
  8. ],
  9. "State": {
  10. "Status": "running", #容器状态
  11. "Running": true, #是否运行
  12. "Paused": false, #是否暂停
  13. "Restarting": false, #是否重启中
  14. "OOMKilled": false, #进程被杀死
  15. "Dead": false, # 已小王
  16. "Pid": 136172, # 容器进程id
  17. "ExitCode": 0, # 退出状态码
  18. "Error": "", #错误信息
  19. "StartedAt": "2022-07-16T01:47:33.598196195Z", #开始启动时间
  20. "FinishedAt": "2022-07-16T01:47:26.919749746Z" # 上一次结束时间
  21. },
  22. "Image": "sha256:3218b38490cec8d31976a40b92e09d61377359eab878db49f025e5d464367f3b", #镜像的sha256算法id
  23. "ResolvConfPath": "/var/lib/docker/containers/572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84/resolv.conf", # resolv.conf域名系统解析器(DNS Resolver)的配置文件路径
  24. "HostnamePath": "/var/lib/docker/containers/572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84/hostname", #当前容器所在的位置
  25. "HostsPath": "/var/lib/docker/containers/572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84/hosts", #容器host文件(域名、IP配置文件)路径
  26. "LogPath": "/var/lib/docker/containers/572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84/572219d3a0ca25a37623a1113f3c8faa6b48d3ab42ae668eac64fcb39cb4dd84-json.log",#容器运行日志文件路径
  27. "Name": "/mysql9", #镜像名称
  28. "RestartCount": 0, #重启个数
  29. "Driver": "overlay2", #存储驱动,联合文件系统
  30. "Platform": "linux", # 运行平台
  31. "MountLabel": "",#挂载标签
  32. "ProcessLabel": "",#进程标签
  33. "AppArmorProfile": "", #Linux内核中的强制访问控制系统配置文件
  34. "ExecIDs": null, #当前容器正在执行 exec的 ID,多个用数组展示
  35. #主机配置
  36. "HostConfig": {
  37. #容器宿主目录绑定
  38. "Binds": [
  39. "/home/mysql8/conf/my.cnf:/etc/mysql/my.cnf",
  40. "/home/mysql8/logs:/logs",
  41. "/home/mysql8/data:/var/lib/mysql",
  42. "/etc/localtime:/etc/localtime"
  43. ],
  44. "ContainerIDFile": "", #???
  45. #日志配置
  46. "LogConfig": {
  47. "Type": "json-file", #文件类型 json
  48. "Config": {}
  49. },
  50. "NetworkMode": "default", #网络模式
  51. #端口绑定信息
  52. "PortBindings": {
  53. "3306/tcp": [
  54. {
  55. "HostIp": "",
  56. "HostPort": "3306"
  57. }
  58. ]
  59. },
  60. #重启策略
  61. "RestartPolicy": {
  62. "Name": "unless-stopped",#自动重启类似always
  63. "MaximumRetryCount": 0 #最大重试次数
  64. },
  65. "AutoRemove": false, #自动移除
  66. "VolumeDriver": "",
  67. "VolumesFrom": null,
  68. "CapAdd": null,
  69. "CapDrop": null,
  70. "CgroupnsMode": "host",
  71. "Dns": [],
  72. "DnsOptions": [],
  73. "DnsSearch": [],
  74. "ExtraHosts": null,
  75. "GroupAdd": null,
  76. "IpcMode": "private",
  77. "Cgroup": "",
  78. "Links": null,
  79. "OomScoreAdj": 0,
  80. "PidMode": "",
  81. "Privileged": true,
  82. "PublishAllPorts": false,
  83. "ReadonlyRootfs": false,
  84. "SecurityOpt": [
  85. "label=disable"
  86. ],
  87. "UTSMode": "",
  88. "UsernsMode": "",
  89. "ShmSize": 67108864,
  90. "Runtime": "runc",
  91. "ConsoleSize": [
  92. 0,
  93. 0
  94. ],
  95. "Isolation": "",
  96. "CpuShares": 0,
  97. "Memory": 0,
  98. "NanoCpus": 0,
  99. "CgroupParent": "",
  100. "BlkioWeight": 0,
  101. "BlkioWeightDevice": [],
  102. "BlkioDeviceReadBps": null,
  103. "BlkioDeviceWriteBps": null,
  104. "BlkioDeviceReadIOps": null,
  105. "BlkioDeviceWriteIOps": null,
  106. "CpuPeriod": 0,
  107. "CpuQuota": 0,
  108. "CpuRealtimePeriod": 0,
  109. "CpuRealtimeRuntime": 0,
  110. "CpusetCpus": "",
  111. "CpusetMems": "",
  112. "Devices": [],
  113. "DeviceCgroupRules": null,
  114. "DeviceRequests": null,
  115. "KernelMemory": 0,
  116. "KernelMemoryTCP": 0,
  117. "MemoryReservation": 0,
  118. "MemorySwap": 0,
  119. "MemorySwappiness": null,
  120. "OomKillDisable": false,
  121. "PidsLimit": null,
  122. "Ulimits": null,
  123. "CpuCount": 0,
  124. "CpuPercent": 0,
  125. "IOMaximumIOps": 0,
  126. "IOMaximumBandwidth": 0,
  127. "MaskedPaths": null,
  128. "ReadonlyPaths": null
  129. },
  130. #镜像管理驱动
  131. "GraphDriver": {
  132. #联合系统分层信息
  133. "Data": {
  134. #镜像层,目录或者文件是只读的
  135. "LowerDir": "/var/lib/docker/overlay2/77f1db351358d953cb1fe55a79e84597d3cbc3844c2dd249a2acdfa15e402627-init/diff:/var/lib/docker/overlay2/b261e67d747a7a769d143f6d4bc9492684b17680256cdf5962f8145acb6b3dab/diff:/var/lib/docker/overlay2/e88c8d60eec4dee423f121636d8b7a560fe2b4739c6c2361d90e290799989120/diff:/var/lib/docker/overlay2/d8f81e30c57461476828fa01d7faad6cc96f893e55684fabf02bf804f76ca2e8/diff:/var/lib/docker/overlay2/b04b2325906657684ef7914d1834a0e510fc7065c78287ce066b0dd5667273c3/diff:/var/lib/docker/overlay2/f09dec6179a52989205fd2931b31996515e06b8048b139f7cc87982df2f497ad/diff:/var/lib/docker/overlay2/c0eab9ee7da29584d4583dd66199346582f1036f69f9989b7da5f8e72f0fa992/diff:/var/lib/docker/overlay2/2a28cd4140717faa03275c600bae785a8a4b0131337bf04267e000f8569aa0f7/diff:/var/lib/docker/overlay2/733a014a49863d79ffb0d86655d8e3b3ceb4a515266e50c09b6cf02d8f81c9c3/diff:/var/lib/docker/overlay2/5da96f62c2672a8590cb920cf541bc3ac636f1aca7babb540d49316c72e7d74a/diff:/var/lib/docker/overlay2/cdf557bd933d8f3809eb2a4b493f376d81e64ee14d0adbd8a74b57d071f63fd6/diff:/var/lib/docker/overlay2/80e0b0ba180d6736e659f56192c214c95d433e59f0aa6d79bfe66d52fb3c7b73/diff:/var/lib/docker/overlay2/4935d32e3ec461a85af88a19fef5872312b4c43a5adf43848b1f3e25353b7ac8/diff",
  136. #容器的挂载点
  137. "MergedDir": "/var/lib/docker/overlay2/77f1db351358d953cb1fe55a79e84597d3cbc3844c2dd249a2acdfa15e402627/merged",
  138. #读写层,在启动一个容器时候会进行创建,所有的对容器数据更改都发生在这里层,upperdir是可读可写的
  139. "UpperDir": "/var/lib/docker/overlay2/77f1db351358d953cb1fe55a79e84597d3cbc3844c2dd249a2acdfa15e402627/diff",
  140. #工作目录
  141. "WorkDir": "/var/lib/docker/overlay2/77f1db351358d953cb1fe55a79e84597d3cbc3844c2dd249a2acdfa15e402627/work"
  142. },
  143. "Name": "overlay2"
  144. },
  145. #挂载配置
  146. "Mounts": [
  147. {
  148. "Type": "bind", #类型
  149. "Source": "/home/mysql8/logs", #来源目录
  150. "Destination": "/logs", #容器目录
  151. "Mode": "", #模式
  152. "RW": true, #读写权限
  153. "Propagation": "rprivate"
  154. #挂载目录实时更新模式 shared、slave、private、rshared、rslave、rprivate
  155. },
  156. {
  157. "Type": "bind",
  158. "Source": "/home/mysql8/data",
  159. "Destination": "/var/lib/mysql",
  160. "Mode": "",
  161. "RW": true,
  162. "Propagation": "rprivate"
  163. },
  164. {
  165. "Type": "bind",
  166. "Source": "/etc/localtime",
  167. "Destination": "/etc/localtime",
  168. "Mode": "",
  169. "RW": true,
  170. "Propagation": "rprivate"
  171. },
  172. {
  173. "Type": "bind",
  174. "Source": "/home/mysql8/conf/my.cnf",
  175. "Destination": "/etc/mysql/my.cnf",
  176. "Mode": "",
  177. "RW": true,
  178. "Propagation": "rprivate"
  179. }
  180. ],
  181. "Config": {
  182. "Hostname": "572219d3a0ca", #容器缩写id
  183. "Domainname": "",
  184. "User": "",
  185. "AttachStdin": false,
  186. "AttachStdout": false,
  187. "AttachStderr": false,
  188. #暴露端口
  189. "ExposedPorts": {
  190. "3306/tcp": {},
  191. "33060/tcp": {}
  192. },
  193. "Tty": false,
  194. "OpenStdin": false,
  195. "StdinOnce": false,
  196. #环境变量配置
  197. "Env": [
  198. "MYSQL_ROOT_PASSWORD=431557313",
  199. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  200. "GOSU_VERSION=1.12",
  201. "MYSQL_MAJOR=8.0",
  202. "MYSQL_VERSION=8.0.27-1debian10"
  203. ],
  204. #设置容器的默认执行的命令,不可以追加命令
  205. "Cmd": [
  206. "mysqld"
  207. ],
  208. #镜像名 服务名+tag版本
  209. "Image": "mysql:8.0.27",
  210. "Volumes": {
  211. "/var/lib/mysql": {}
  212. },
  213. #工作目录
  214. "WorkingDir": "",
  215. #设置容器的默认执行的命令,可以追加命令
  216. "Entrypoint": [
  217. "docker-entrypoint.sh"
  218. ],
  219. "OnBuild": null,#Dockerfile文件构建
  220. "Labels": {}
  221. },
  222. #网络设置
  223. "NetworkSettings": {
  224. "Bridge": "", #网桥
  225. #沙箱id
  226. "SandboxID": "9d8795184ee28e903bb503b42519d5f56a622977f49e4255e771dfcb1c8bdaf3",
  227. "HairpinMode": false, #是否开启发卡模式
  228. "LinkLocalIPv6Address": "",
  229. "LinkLocalIPv6PrefixLen": 0,
  230. #端口配置
  231. "Ports": {
  232. "3306/tcp": [
  233. {
  234. "HostIp": "0.0.0.0",
  235. "HostPort": "3306"
  236. },
  237. {
  238. "HostIp": "::", #外网访问
  239. "HostPort": "3306" #暴力端口
  240. }
  241. ],
  242. "33060/tcp": null
  243. },
  244. "SandboxKey": "/var/run/docker/netns/9d8795184ee2", #沙盒密钥路径
  245. "SecondaryIPAddresses": null,
  246. "SecondaryIPv6Addresses": null,
  247. "EndpointID": "826898658eec96e305763ce63e6505c4c0e5d152872bf8ae517f73371a8d015e",
  248. "Gateway": "172.17.0.1", #网关地址
  249. "GlobalIPv6Address": "",
  250. "GlobalIPv6PrefixLen": 0,
  251. "IPAddress": "172.17.0.3",
  252. "IPPrefixLen": 16,
  253. "IPv6Gateway": "",
  254. "MacAddress": "02:42:ac:11:00:03", #MAC地址
  255. "Networks": {
  256. "bridge": {
  257. "IPAMConfig": null,
  258. "Links": null,
  259. "Aliases": null,
  260. "NetworkID": "376cfaed3501614c09972655643d3d974e434548773d140c0040d9c268294e51",
  261. "EndpointID": "826898658eec96e305763ce63e6505c4c0e5d152872bf8ae517f73371a8d015e",
  262. "Gateway": "172.17.0.1",
  263. "IPAddress": "172.17.0.3",
  264. "IPPrefixLen": 16,
  265. "IPv6Gateway": "",
  266. "GlobalIPv6Address": "",
  267. "GlobalIPv6PrefixLen": 0,
  268. "MacAddress": "02:42:ac:11:00:03",
  269. "DriverOpts": null
  270. }
  271. }
  272. }
  273. }
  274. ]

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/305574
推荐阅读
相关标签
  

闽ICP备14008679号