当前位置:   article > 正文

docker 查看容器启动命令(已运行的容器)_docker查看容器启动命令

docker查看容器启动命令

   eg:

1 docker ps 查看正在运行的容器:

 通过docker ps命令
该命令主要是为了详细展示查看运行时的command参数
docker ps -a --no-trunc | grep container_name   # 通过docker --no-trunc参数来详细展示容器运行命令

通过docker inspect命令
使用docker inspect,但是docker inspect打印的是json文件,需要挑选字段查看,容器的参数信息都能从json文件中解析出来。
1,在容器外部,物理机上,可以用下面命令
docker inspect <container_name>   # 可以是container_name或者container_id

eg:

  1. [root@128 ~]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 547880f43cf1 mysql:8.0.31 "docker-entrypoint.s…" 15 minutes ago Up 15 minutes 33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp mysql-8.0.31
  4. e02f22dc442c mysql:5.7 "docker-entrypoint.s…" 25 hours ago Up 18 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
  5. [root@128 ~]# docker ps -a --no-trunc | grep 547880f43cf1
  6. 547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232 mysql:8.0.31 "docker-entrypoint.sh mysqld" 15 minutes ago Up 15 minutes 33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp mysql-8.0.31
  7. [root@128 ~]# docker inspect 547880f43cf1
  8. [
  9. {
  10. "Id": "547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232",
  11. "Created": "2022-12-07T10:13:46.80942044Z",
  12. "Path": "docker-entrypoint.sh",
  13. "Args": [
  14. "mysqld"
  15. ],
  16. "State": {
  17. "Status": "running",
  18. "Running": true,
  19. "Paused": false,
  20. "Restarting": false,
  21. "OOMKilled": false,
  22. "Dead": false,
  23. "Pid": 5469,
  24. "ExitCode": 0,
  25. "Error": "",
  26. "StartedAt": "2022-12-07T10:13:47.159621124Z",
  27. "FinishedAt": "0001-01-01T00:00:00Z"
  28. },
  29. "Image": "sha256:a3a2968869cf080dbbd2adaac9e4075cc358b50a1451ff5e2b9ae90551a4735f",
  30. "ResolvConfPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/resolv.conf",
  31. "HostnamePath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/hostname",
  32. "HostsPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/hosts",
  33. "LogPath": "/var/lib/docker/containers/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232/547880f43cf176d2a826ae26f9f04bbe637ca56ec5d92df25a78d24ec23ed232-json.log",
  34. "Name": "/mysql-8.0.31",
  35. "RestartCount": 0,
  36. "Driver": "overlay2",
  37. "Platform": "linux",
  38. "MountLabel": "",
  39. "ProcessLabel": "",
  40. "AppArmorProfile": "",
  41. "ExecIDs": null,
  42. "HostConfig": {
  43. "Binds": [
  44. "/mydata/mysql-8.0.31/log:/var/log/mysql",
  45. "/mydata/mysql-8.0.31/data:/var/lib/mysql"
  46. ],
  47. "ContainerIDFile": "",
  48. "LogConfig": {
  49. "Type": "json-file",
  50. "Config": {}
  51. },
  52. "NetworkMode": "default",
  53. "PortBindings": {
  54. "3306/tcp": [
  55. {
  56. "HostIp": "",
  57. "HostPort": "3301"
  58. }
  59. ]
  60. },
  61. "RestartPolicy": {
  62. "Name": "no",
  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": false,
  82. "PublishAllPorts": false,
  83. "ReadonlyRootfs": false,
  84. "SecurityOpt": null,
  85. "UTSMode": "",
  86. "UsernsMode": "",
  87. "ShmSize": 67108864,
  88. "Runtime": "runc",
  89. "ConsoleSize": [
  90. 0,
  91. 0
  92. ],
  93. "Isolation": "",
  94. "CpuShares": 0,
  95. "Memory": 0,
  96. "NanoCpus": 0,
  97. "CgroupParent": "",
  98. "BlkioWeight": 0,
  99. "BlkioWeightDevice": [],
  100. "BlkioDeviceReadBps": null,
  101. "BlkioDeviceWriteBps": null,
  102. "BlkioDeviceReadIOps": null,
  103. "BlkioDeviceWriteIOps": null,
  104. "CpuPeriod": 0,
  105. "CpuQuota": 0,
  106. "CpuRealtimePeriod": 0,
  107. "CpuRealtimeRuntime": 0,
  108. "CpusetCpus": "",
  109. "CpusetMems": "",
  110. "Devices": [],
  111. "DeviceCgroupRules": null,
  112. "DeviceRequests": null,
  113. "KernelMemory": 0,
  114. "KernelMemoryTCP": 0,
  115. "MemoryReservation": 0,
  116. "MemorySwap": 0,
  117. "MemorySwappiness": null,
  118. "OomKillDisable": false,
  119. "PidsLimit": null,
  120. "Ulimits": null,
  121. "CpuCount": 0,
  122. "CpuPercent": 0,
  123. "IOMaximumIOps": 0,
  124. "IOMaximumBandwidth": 0,
  125. "MaskedPaths": [
  126. "/proc/asound",
  127. "/proc/acpi",
  128. "/proc/kcore",
  129. "/proc/keys",
  130. "/proc/latency_stats",
  131. "/proc/timer_list",
  132. "/proc/timer_stats",
  133. "/proc/sched_debug",
  134. "/proc/scsi",
  135. "/sys/firmware"
  136. ],
  137. "ReadonlyPaths": [
  138. "/proc/bus",
  139. "/proc/fs",
  140. "/proc/irq",
  141. "/proc/sys",
  142. "/proc/sysrq-trigger"
  143. ]
  144. },
  145. "GraphDriver": {
  146. "Data": {
  147. "LowerDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1-init/diff:/var/lib/docker/overlay2/e6ce4810d05ed0bdca975287151d5edcb8f5b4e3472fba848ecbd0858a83c27d/diff:/var/lib/docker/overlay2/0bd4abf22bc8fd1840c48d50034d525576608654eac3696820bdecca885869e1/diff:/var/lib/docker/overlay2/aa9ffa3d8ca28910870afed61cbb7a8b5954b633b6c51ddec94b33f45fd7c69a/diff:/var/lib/docker/overlay2/7832e98417573f093c97491e70941e1a09e9a6e4e49b4407644cc367fdbeb37e/diff:/var/lib/docker/overlay2/74b73e21fc743a650a4064f4e771fd65aca511cf433aee93cc6eef2f3a91d787/diff:/var/lib/docker/overlay2/0df122c8a1629d74c09d97e489932b0812da34d28734118287934acbf3e8e985/diff:/var/lib/docker/overlay2/6f48c0c0c5bb4f2d96900b9eb4d20409a066a9bf3c104171e5dd33f28dbe6301/diff:/var/lib/docker/overlay2/37869951120d01076a5bc57e0c04c8f466a0b0b37e06357653b27b2fc9638a1d/diff:/var/lib/docker/overlay2/c2414c698ebdc9f0bacedf53387c75aa6cb000720ff019d989e4daa9d9c0929f/diff:/var/lib/docker/overlay2/099e69b07f239a7747f754a2598aec804655f5d6d7beb9ffb85932c490ec13d1/diff:/var/lib/docker/overlay2/9be3057383e74825462c49286ffa30853fb87f6d975ad40459e12972538ce21c/diff",
  148. "MergedDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/merged",
  149. "UpperDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/diff",
  150. "WorkDir": "/var/lib/docker/overlay2/b4d5fed9eb97224cd6834e36509728032ceac386e863a483d7e2770f611eb8d1/work"
  151. },
  152. "Name": "overlay2"
  153. },
  154. "Mounts": [
  155. {
  156. "Type": "bind",
  157. "Source": "/mydata/mysql-8.0.31/log",
  158. "Destination": "/var/log/mysql",
  159. "Mode": "",
  160. "RW": true,
  161. "Propagation": "rprivate"
  162. },
  163. {
  164. "Type": "bind",
  165. "Source": "/mydata/mysql-8.0.31/data",
  166. "Destination": "/var/lib/mysql",
  167. "Mode": "",
  168. "RW": true,
  169. "Propagation": "rprivate"
  170. }
  171. ],
  172. "Config": {
  173. "Hostname": "547880f43cf1",
  174. "Domainname": "",
  175. "User": "",
  176. "AttachStdin": false,
  177. "AttachStdout": false,
  178. "AttachStderr": false,
  179. "ExposedPorts": {
  180. "3306/tcp": {},
  181. "33060/tcp": {}
  182. },
  183. "Tty": false,
  184. "OpenStdin": false,
  185. "StdinOnce": false,
  186. "Env": [
  187. "MYSQL_ROOT_PASSWORD=123456",
  188. "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
  189. "GOSU_VERSION=1.14",
  190. "MYSQL_MAJOR=8.0",
  191. "MYSQL_VERSION=8.0.31-1.el8",
  192. "MYSQL_SHELL_VERSION=8.0.31-1.el8"
  193. ],
  194. "Cmd": [
  195. "mysqld"
  196. ],
  197. "Image": "mysql:8.0.31",
  198. "Volumes": {
  199. "/var/lib/mysql": {}
  200. },
  201. "WorkingDir": "",
  202. "Entrypoint": [
  203. "docker-entrypoint.sh"
  204. ],
  205. "OnBuild": null,
  206. "Labels": {}
  207. },
  208. "NetworkSettings": {
  209. "Bridge": "",
  210. "SandboxID": "f82246141707b2ab4578ce193cdf42b9dd82fef9d8ca805c4b07b6af90867ffc",
  211. "HairpinMode": false,
  212. "LinkLocalIPv6Address": "",
  213. "LinkLocalIPv6PrefixLen": 0,
  214. "Ports": {
  215. "3306/tcp": [
  216. {
  217. "HostIp": "0.0.0.0",
  218. "HostPort": "3301"
  219. },
  220. {
  221. "HostIp": "::",
  222. "HostPort": "3301"
  223. }
  224. ],
  225. "33060/tcp": null
  226. },
  227. "SandboxKey": "/var/run/docker/netns/f82246141707",
  228. "SecondaryIPAddresses": null,
  229. "SecondaryIPv6Addresses": null,
  230. "EndpointID": "386a6348d0fd2e9119e7d427ed2df21bf03f4a88c485b50cf142d6c0b0f08f83",
  231. "Gateway": "172.17.0.1",
  232. "GlobalIPv6Address": "",
  233. "GlobalIPv6PrefixLen": 0,
  234. "IPAddress": "172.17.0.2",
  235. "IPPrefixLen": 16,
  236. "IPv6Gateway": "",
  237. "MacAddress": "02:42:ac:11:00:02",
  238. "Networks": {
  239. "bridge": {
  240. "IPAMConfig": null,
  241. "Links": null,
  242. "Aliases": null,
  243. "NetworkID": "65f89f72b915b6ae63526860f40f2e701bfcc1c689301d757230f7a522379d35",
  244. "EndpointID": "386a6348d0fd2e9119e7d427ed2df21bf03f4a88c485b50cf142d6c0b0f08f83",
  245. "Gateway": "172.17.0.1",
  246. "IPAddress": "172.17.0.2",
  247. "IPPrefixLen": 16,
  248. "IPv6Gateway": "",
  249. "GlobalIPv6Address": "",
  250. "GlobalIPv6PrefixLen": 0,
  251. "MacAddress": "02:42:ac:11:00:02",
  252. "DriverOpts": null
  253. }
  254. }
  255. }
  256. }
  257. ]

如上所示,这个是我这547880f43cf1 容器的详细信息

然后可以定制化输出上面的信息:显示上面内容的某一部分信息

  1. docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' <container_name> # format是go语言的template,还有其他的用法
  2. docker inspect --format='{{.Mounts}}' <container_name>
  3. docker inspect --format='{{.HostConfig.Binds}}' <container_name>
  4. docker inspect --format='{{.HostConfig.PortBindings}}' <container_name>

eg: 还可以将上面的修改为别的内容,我这边关注file和port两个

  1. [root@128 ~]# docker ps
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 547880f43cf1 mysql:8.0.31 "docker-entrypoint.s…" 18 minutes ago Up 18 minutes 33060/tcp, 0.0.0.0:3301->3306/tcp, :::3301->3306/tcp mysql-8.0.31
  4. e02f22dc442c mysql:5.7 "docker-entrypoint.s…" 25 hours ago Up 22 minutes 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
  5. [root@128 ~]# docker inspect --format='{{.Mounts}}' 547880f43cf1
  6. [{bind /mydata/mysql-8.0.31/log /var/log/mysql true rprivate} {bind /mydata/mysql-8.0.31/data /var/lib/mysql true rprivate}]
  7. [root@128 ~]# docker inspect --format='{{.NetworkSettings.Networks.bridge.IPAddress}}' 547880f43cf1
  8. 172.17.0.2
  9. [root@128 ~]# docker inspect --format='{{.HostConfig.Binds}}' 547880f43cf1
  10. [/mydata/mysql-8.0.31/log:/var/log/mysql /mydata/mysql-8.0.31/data:/var/lib/mysql]
  11. [root@128 ~]# docker inspect --format='{{.HostConfig.PortBindings}}' 547880f43cf1
  12. map[3306/tcp:[{ 3301}]]
  13. [root@128 ~]#

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

闽ICP备14008679号