Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

The docker inspect command

The docker inspect command

Docker Command ReferenceDocker Command Reference


docker inspect This command retrieves detailed information about Docker objects (containers, images, volumes, networks, etc.).

docker inspect It returns detailed information in JSON format, helping users understand an object's configuration and status.

Syntax

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

OPTIONS description:

Example

1. Inspect a container

docker inspect my_container

Return detailed information about the my_container container.

2. Inspect an image



docker inspect my_image

Return detailed information about the my_image image.

3. Inspect a volume



docker inspect my_volume

Return detailed information about the my_volume volume.

4. Inspect a network



docker inspect my_network

Return detailed information about the my_network network.

5. Format the output



docker inspect --format '{{ .State.Running }}' my_container

Return the running status of the my_container container, formatted as a boolean value.

6. Inspect multiple objects



docker inspect my_container my_image

Return detailed information about the my_container container and the my_image image.

Example output

Container information:

docker inspect my_container

Output:

[

    {

        "Id": "d2f5e3f19a6a",

        "Created": "2024-07-23T00:00:00Z",

        "Path": "bash",

        "Args": [],

        "State": {

            "Status": "running",

            "Running": true,

            "Paused": false,

            "Restarting": false,

            "OOMKilled": false,

            "Dead": false,

            "Pid": 12345,

            "ExitCode": 0,

            "Error": "",

            "StartedAt": "2024-07-23T00:00:00Z",

            "FinishedAt": "0001-01-01T00:00:00Z"

        },

        "Image": "sha256:abc123",

        "ResolvConfPath": "/var/lib/docker/containers/d2f5e3f19a6a/resolv.conf",

        "HostnamePath": "/var/lib/docker/containers/d2f5e3f19a6a/hostname",

        "HostsPath": "/var/lib/docker/containers/d2f5e3f19a6a/hosts",

        "LogPath": "/var/lib/docker/containers/d2f5e3f19a6a/d2f5e3f19a6a-json.log",

        "Name": "/my_container",

        "RestartCount": 0,

        "Driver": "overlay2",

        "Platform": "linux",

        "MountLabel": "",

        "ProcessLabel": "",

        "AppArmorProfile": "",

        "ExecIDs": null,

        "HostConfig": {

            "Binds": null,

            "ContainerIDFile": "",

            "LogConfig": {

                "Type": "json-file",

                "Config": {}

            },

            "NetworkMode": "default",

            "PortBindings": {},

            "RestartPolicy": {

                "Name": "no",

                "MaximumRetryCount": 0

            },

            "AutoRemove": false,

            "VolumeDriver": "",

            "VolumesFrom": null,

            "CapAdd": null,

            "CapDrop": 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": null,

            "BlkioDeviceReadBps": null,

            "BlkioDeviceWriteBps": null,

            "BlkioDeviceReadIOps": null,

            "BlkioDeviceWriteIOps": null,

            "CpuPeriod": 0,

            "CpuQuota": 0,

            "CpuRealtimePeriod": 0,

            "CpuRealtimeRuntime": 0,

            "CpusetCpus": "",

            "CpusetMems": "",

            "Devices": null,

            "DiskQuota": 0,

            "KernelMemory": 0,

            "MemoryReservation": 0,

            "MemorySwap": 0,

            "MemorySwappiness": null,

            "OomKillDisable": false,

            "PidsLimit": null,

            "Ulimits": null,

            "CpuCount": 0,

            "CpuPercent": 0,

            "IOMaximumIOps": 0,

            "IOMaximumBandwidth": 0,

            "Mounts": [],

            "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/l/abc123/diff",

                "MergedDir": "/var/lib/docker/overlay2/merged",

                "UpperDir": "/var/lib/docker/overlay2/upper",

                "WorkDir": "/var/lib/docker/overlay2/work"

            },

            "Name": "overlay2"

        },

        "Mounts": [],

        "Config": {

            "Hostname": "d2f5e3f19a6a",

            "Domainname": "",

            "User": "",

            "AttachStdin": false,

            "AttachStdout": false,

            "AttachStderr": false,

            "ExposedPorts": {},

            "Tty": false,

            "OpenStdin": false,

            "StdinOnce": false,

            "Env": [

                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

            ],

            "Cmd": [

                "bash"

            ],

            "Image": "ubuntu",

            "Volumes": null,

            "WorkingDir": "",

            "Entrypoint": null,

            "OnBuild": null,

            "Labels": {}

        },

        "NetworkSettings": {

            "Bridge": "",

            "SandboxID": "abc123",

            "HairpinMode": false,

            "LinkLocalIPv6Address": "",

            "LinkLocalIPv6PrefixLen": 0,

            "Ports": {},

            "SandboxKey": "/var/run/docker/netns/abc123",

            "SecondaryIPAddresses": null,

            "SecondaryIPv6Addresses": null,

            "EndpointID": "abc123",

            "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": "abc123",

                    "EndpointID": "abc123",

                    "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

                }

            }

        }

    }

]

Use Cases

docker inspect This command is one of the most powerful and practical commands in Docker, allowing users to obtain detailed information about containers, images, volumes, networks, and other objects. By using it, users can gain in-depth understanding and management of the configuration and status of Docker objects, meeting various debugging, monitoring, and management needs.


Docker Command ReferenceDocker Command Reference