Docker 查詢容器配置資訊的方法如下。
例如下面用docker ps
檢視目前有一運行中的nginx容器如下,容器ID為2e33400c9c6c
,名稱為webserver
。
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e33400c9c6c nginx "nginx -g 'daemon of…" 6 weeks ago Up 52 minutes 0.0.0.0:80->80/tcp webserver
使用docker inspect <CONTAINER_NAME/CONTAINER_ID>
指令可檢視容器的詳細資訊,內容以json格式顯示。<CONTAINER_ID>
為容器ID;<CONTAINER_NAME>
為容器名稱。
例如用docker inspect 2e33400c9c6c
檢視運行中的nginx容器詳細資訊如下。
$ docker inspect 2e33400c9c6c
[
{
"Id": "2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4",
"Created": "2020-05-01T14:42:01.850230454Z",
"Path": "nginx",
"Args": [
"-g",
"daemon off;"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 8340,
"ExitCode": 0,
"Error": "",
"StartedAt": "2020-06-13T13:13:06.832167668Z",
"FinishedAt": "2020-05-02T03:54:48.643961581Z"
},
"Image": "sha256:602e111c06b6934013578ad80554a074049c59441d9bcd963cb4a7feccede7a5",
"ResolvConfPath": "/mnt/sda1/var/lib/docker/containers/2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4/resolv.conf",
"HostnamePath": "/mnt/sda1/var/lib/docker/containers/2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4/hostname",
"HostsPath": "/mnt/sda1/var/lib/docker/containers/2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4/hosts",
"LogPath": "/mnt/sda1/var/lib/docker/containers/2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4/2e33400c9c6c18a96242b2e6d36f8dc04fa12a4c70b1135a32e308583b1148c4-json.log",
"Name": "/webserver",
"RestartCount": 0,
"Driver": "overlay2",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"NetworkMode": "default",
"PortBindings": {
"80/tcp": [
{
"HostIp": "",
"HostPort": "80"
}
]
},
"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": [
31,
80
],
"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": "/mnt/sda1/var/lib/docker/overlay2/512e19056bc7a80f60bd16d4a7166f15b248b6c3e9590bb6c40ecc3f7993e87f-init/diff:/mnt/sda1/var/lib/docker/overlay2/33d75eedda0fb55b2d12e1b285e65cfeb38d6131576a3c639e3c43a1d7a80717/diff:/mnt/sda1/var/lib/docker/overlay2/070b9d03ba84f3a122ce436cd8c2a48f39ccd3aaab950836cf0c3fe0610eccb5/diff:/mnt/sda1/var/lib/docker/overlay2/6860df7ad91c269b48309a72895ac390a8f7d3b5679aac5b909d3748170e547d/diff",
"MergedDir": "/mnt/sda1/var/lib/docker/overlay2/512e19056bc7a80f60bd16d4a7166f15b248b6c3e9590bb6c40ecc3f7993e87f/merged",
"UpperDir": "/mnt/sda1/var/lib/docker/overlay2/512e19056bc7a80f60bd16d4a7166f15b248b6c3e9590bb6c40ecc3f7993e87f/diff",
"WorkDir": "/mnt/sda1/var/lib/docker/overlay2/512e19056bc7a80f60bd16d4a7166f15b248b6c3e9590bb6c40ecc3f7993e87f/work"
},
"Name": "overlay2"
},
"Mounts": [],
"Config": {
"Hostname": "2e33400c9c6c",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"ExposedPorts": {
"80/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"NGINX_VERSION=1.17.10",
"NJS_VERSION=0.3.9",
"PKG_RELEASE=1~buster"
],
"Cmd": [
"nginx",
"-g",
"daemon off;"
],
"Image": "nginx",
"Volumes": null,
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {
"maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "8a86bbf004aec994343f28fb21ea9058447aa54a8c194430f107bc510da2ff87",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"80/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "80"
}
]
},
"SandboxKey": "/var/run/docker/netns/8a86bbf004ae",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "5b9d62392965614b521f0d98add96df4101c0820ad79476932383155016cf034",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:02",
"Networks": {
"bridge": {
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "802679f95dae3349138d4ece6194cd4db54da1c5efc1df4406b7619829a1e3ad",
"EndpointID": "5b9d62392965614b521f0d98add96df4101c0820ad79476932383155016cf034",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "02:42:ac:11:00:02",
"DriverOpts": null
}
}
}
}
]
若只要看某一子項目的資訊,使用
docker inspect --format='{{.ItemName}}' <CONTAINER_NAME/CONTAINER_ID>
。
ItemName
為子屬性的名稱,可以後接多個,例如'{{.Config.Hostname}}'
。
例如用docker inspect --format='{{.Config.Hostname}}' webserver
檢視nginx的hostname。
$ docker inspect --format='{{.Config.Hostname}}' webserver
2e33400c9c6c
沒有留言:
張貼留言