Docker inspect命令具有什么功能呢?

书欣 Docker 发布时间:2023-01-18 17:26:51 阅读数:14669 1
下文笔者讲述Docker中inspect命令的功能简介说明,如下所示
docker inspect功能:
    获取容器及镜像中的元数据

docker inspect命令语法

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

OPTIONS说明:
  -f:指定返回值的模板文件
  -s:显示总的文件大小
  --type:为指定类型返回JSON
例: docker inspect命令的示例分享
//查看nginx的元数据
[root@node0 ~]# docker inspect cb8
[
    {
        "Id": "cb8c9febda6c913fc7dff9ed88f5460838859638b228374e434af0f5d356f078",
        "Created": "2023-01-17T23:11:08.919839637Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 80829,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-01-17T23:27:01.28149458Z",
            "FinishedAt": "2023-01-17T23:15:23.59976747Z"
        },
        "Image": "sha256:605c77e624ddb75e6110f997c58876baa13f8754486b461117934b24a9dc3a85",
        "ResolvConfPath": "/var/lib/docker/containers/cb8c9febda6c913fc7dff9ed88f5460838859638b228374e434af0f5d356f078/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/cb8c9febda6c913fc7dff9ed88f5460838859638b228374e434af0f5d356f078/hostname",
        "HostsPath": "/var/lib/docker/containers/cb8c9febda6c913fc7dff9ed88f5460838859638b228374e434af0f5d356f078/hosts",
        "LogPath": "",
        "Name": "/nginx",
        "RestartCount": 0,
        "Driver": "overlay2",
        "MountLabel": "system_u:object_r:svirt_sandbox_file_t:s0:c633,c1021",
        "ProcessLabel": "system_u:system_r:svirt_lxc_net_t:s0:c633,c1021",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": null,
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "journald",
                "Config": {}
            },
            "NetworkMode": "default",
            "PortBindings": {
                "80/tcp": [
                    {
                        "HostIp": "",
                        "HostPort": "80"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "no",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "docker-runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": -1,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": null,
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0
        },
        "GraphDriver": {
            "Name": "overlay2",
            "Data": {
                "LowerDir": "/var/lib/docker/overlay2/1207fef1586e816de1548d5524ea680a6fa7b2a2d07cabf2bc5a8382664a604a-init/diff:/var/l
ib/docker/overlay2/c1efa4a731960feb0b8a8d64efcf7b4ddf35e1f09fb8e3d3cee1892f44f03396/diff:/var/lib/docker/overlay2/52e0dbe8fd1aebb192406004de4bdbeab959fa70edb530bfce17d92a8887d00a/diff:/var/lib/docker/overlay2/e8efaa04c24d8a1c07f90bda99c5d77f59a2ca3cf6b37a2c288182685cc08e71/diff:/var/lib/docker/overlay2/a8aa8a964a46baa3c8a83c5304fc3830474f135c5f5b94fcb30b96ce6826b493/diff:/var/lib/docker/overlay2/4beaff3bd33edc1b42cab33a6d967122a7a5fd43cb104bb722f4ca867aac1072/diff:/var/lib/docker/overlay2/74cd3eb0d5af227ca4970ec93014831fae2e64e41864e772cd8b897560d386ce/diff",                "MergedDir": "/var/lib/docker/overlay2/1207fef1586e816de1548d5524ea680a6fa7b2a2d07cabf2bc5a8382664a604a/merged",
                "UpperDir": "/var/lib/docker/overlay2/1207fef1586e816de1548d5524ea680a6fa7b2a2d07cabf2bc5a8382664a604a/diff",
                "WorkDir": "/var/lib/docker/overlay2/1207fef1586e816de1548d5524ea680a6fa7b2a2d07cabf2bc5a8382664a604a/work"
            }
        },
        "Mounts": [],
        "Config": {
            "Hostname": "cb8c9febda6c",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": true,
            "AttachStderr": true,
            "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.21.5",
                "NJS_VERSION=0.7.1",
                "PKG_RELEASE=1~bullseye"
            ],
            "Cmd": [
                "nginx",
                "-g",
                "daemon off;"
            ],
            "Image": "nginx",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": [
                "/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "maintainer": "NGINX Docker Maintainers <docker-maint@nginx.com>"
            },
            "StopSignal": "SIGQUIT"
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "2d8387ed58eb361477d9cf4ee8c5bbe567ebea88f686c291934e0493228f2a3e",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {
                "80/tcp": [
                    {
                        "HostIp": "0.0.0.0",
                        "HostPort": "80"
                    }
                ]
            },
            "SandboxKey": "/var/run/docker/netns/2d8387ed58eb",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "145a54679bb895fbe992d93313d05f935e4372f44ef2324fa7cbec11be790d62",
            "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": "e4556eaad092452996158af2848970635fbfa6695adf8f6810729efaa9d75e3d",
                    "EndpointID": "145a54679bb895fbe992d93313d05f935e4372f44ef2324fa7cbec11be790d62",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:11:00:02"
                }
            }
        }
    }
]


//查看nginx容器的IP地址
[root@node0 ~]# docker inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' nginx
172.17.0.2
版权声明

本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。

本文链接: https://www.Java265.com/docker/202301/5440.html

最近发表

热门文章

好文推荐

Java265.com

https://www.java265.com

站长统计|粤ICP备14097017号-3

Powered By Java265.com信息维护小组

使用手机扫描二维码

关注我们看更多资讯

java爱好者