官方地址[https://docs.docker.com/engine/reference/commandline/inspect/#examples}(https://docs.docker.com/engine/reference/commandline/inspect/#examples)
可以看看比较优秀的相关博客https://www.cnblogs.com/kevingrace/p/6424476.html
- 查看容器的Pid
docker inspect --format {{.State.Pid}} <container_name_or_ID>
- 查看容器的日志
docker inspect --format='{{.LogPath}}' $INSTANCE_ID
- Get an instance’s IP address
docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $INSTANCE_ID
- Get an instance’s image name
docker inspect --format='{{.Config.Image}}' $INSTANCE_ID
- List all port bindings列出所有绑定的端口
docker inspect --format='{{range $p, $conf := .NetworkSettings.Ports}} {{$p}} -> {{(index $conf 0).HostPort}} {{end}}' $INSTANCE_ID
- Find a specific port mapping查看某个映射到主机的端口
docker inspect --format='{{(index (index .NetworkSettings.Ports "8787/tcp") 0).HostPort}}' $INSTANCE_ID
- json格式的Config
docker inspect --format='{{json .Config}}' $INSTANCE_ID
docker inspect ID
顶级的大概有这几大块,
Id
Created
Path
Args
State
Image
ResolvConfPath
HostnamePath
HostsPath
LogPath
Name
RestartCount
Driver
Platform
MountLabel
ProcessLabel
AppArmorProfile
ExecIDs
HostConfig
GraphDriver
Mounts
Config
NetworkSettings
以下是详细的参考
{
"Id": "d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309",
"Created": "2020-09-21T07:47:55.203816691Z",
"Path": "docker-entrypoint.sh",
"Args": [
"mysqld"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 17070,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-09-21T07:47:55.506640913Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "sha256:718a6da099d82183c064a964523c0deca80619cb033aadd15854771fe592a480",
"ResolvConfPath": "/var/lib/docker/containers/d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309/hostname",
"HostsPath": "/var/lib/docker/containers/d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309/hosts",
"LogPath": "/var/lib/docker/containers/d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309/d0ec895c60edb066db24e77f06f2e3c5452fd898f0f3cbbc300525ff74d43309-json.log",
"Name": "/mysql5.7",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": [
"41af535c87b3f910028127cca1805334e07ce76241c9fe3137f911708601dcca",
"a38755657ed92a3df475a2e730b0b07dbc8d3311776ba98e61e6f582db1df30c"
],
"HostConfig": {
"Binds": [
"/etc/mysql:/etc/mysql/conf.d",
"/data/mysql:/var/lib/mysql"
],
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"3306/tcp": [
{
"HostIp": "",
"HostPort": "50000"
}
]
},
"RestartPolicy": {
"Name": "always",
"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/235832d2e0b172eff0405b7021d025f25432d9eada1e49730f24f046607a5db4-init/diff:/var/lib/docker/overlay2/f4fc92239259e7637520c5a560364c5bcc1d2adc4d25635f19bef0f638093178/diff:/var/lib/docker/overlay2/adf1b9faa5f7620ece22ffcf3cb51329482c9620defeae8238cb5b9b73dce2fd/diff:/var/lib/docker/overlay2/dbe4335f3a81258c9c94dfa6d25b63a7feb7c3258fb56310b5adc677a2328c17/diff:/var/lib/docker/overlay2/0018339bb1eabf67a2c8b0e8abbccc1856d8a0547b7b36beefac384e8ef46256/diff:/var/lib/docker/overlay2/04b0281b5916b610bacb45e83073580833470ed66eec722b5f8afa1c07a61e03/diff:/var/lib/docker/overlay2/3426cbb388bb91fac41fa3026de42e9dd6fef01cd9db09966532c89b8b515958/diff:/var/lib/docker/overlay2/8c15524c85f83ef376e8528b46affee4d44d315f480f6c6b874abcacc4a51b6c/diff:/var/lib/docker/overlay2/42caa3420f8097b67720be5f490bc2fba288f5a81a61eee478861aeb63013576/diff:/var/lib/docker/overlay2/86943e134693d419e14834b87728655fac0e0634529c05fc419222859dbac86c/diff:/var/lib/docker/overlay2/6de0c9fcfff839e5b9212bc8d18d7e8bdb3ceb8354a8ee7976b89544891c0b19/diff:/var/lib/docker/overlay2/fd73c7733caae1e26067ce20171a6104f687b39712fb605b510d9f2f68c86913/diff",
"MergedDir": "/var/lib/docker/overlay2/235832d2e0b172eff0405b7021d025f25432d9eada1e49730f24f046607a5db4/merged",
"UpperDir": "/var/lib/docker/overlay2/235832d2e0b172eff0405b7021d025f25432d9eada1e49730f24f046607a5db4/diff",
"WorkDir": "/var/lib/docker/overlay2/235832d2e0b172eff0405b7021d025f25432d9eada1e49730f24f046607a5db4/work"
},
"Name": "overlay2"
},
"Mounts": [
{
"Type": "bind",
"Source": "/etc/mysql",
"Destination": "/etc/mysql/conf.d",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/data/mysql",
"Destination": "/var/lib/mysql",
"Mode": "",
"RW": true,
"Propagation": "rprivate"
}
],
"Config": {
"Hostname": "d0ec895c60ed",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"3306/tcp": {},
"33060/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"MYSQL_ROOT_PASSWORD=Dreamfuture88",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"GOSU_VERSION=1.12",
"MYSQL_MAJOR=5.7",
"MYSQL_VERSION=5.7.31-1debian10"
],
"Cmd": [
"mysqld"
],
"Image": "mysql:5.7",
"Volumes": {
"/var/lib/mysql": {}
},
"WorkingDir": "",
"Entrypoint": [
"docker-entrypoint.sh"
],
"OnBuild": null,
"Labels": {}
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "9031196acef6b974b58e2a2ec704c5b5117111b6704b3ecea300e7f0ffb37da6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"3306/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "50000"
}
],
"33060/tcp": null
},
"SandboxKey": "/var/run/docker/netns/9031196acef6",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "feb3f12a6f73673529ffc9a68a3d1e041d3aa8b80356db90e55b0c3baa1d8250",
"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": "2cf26d1ec7d709a12d9aac67894a9500bf3d1bb217bc954259765152ea65b6fa",
"EndpointID": "feb3f12a6f73673529ffc9a68a3d1e041d3aa8b80356db90e55b0c3baa1d8250",
"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
}
}
}
}