curl command for docker inspect

1.2k Views Asked by At

I have seen some curl commands to search, pull image etc from docker. Some examples are provided here

What is the equalent code of sudo docker inspect nginx?

In terminal its output is as follows.

[
{
    "Id": "319d2015d149943ff4d2a20ddea7d7e5ce06a64bbab1792334c0d3273bbbff1e",
    "Parent": "107c338c1d31577c86670a0aa070ed903c9e00802838f9ffb8420a6acfb3dbaf",
    "Comment": "",
    "Created": "2015-06-16T21:50:45.835843344Z",
    "Container": "e9b1150a37d45ba2335ee36436e7d435c1ce1d2960720cd1d06c194c2db13d8f",
    "ContainerConfig": {
        "Hostname": "6c732c6044b7",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "PortSpecs": null,
        "ExposedPorts": {
            "443/tcp": {},
            "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.9.2-1~jessie"
        ],
        "Cmd": [
            "/bin/sh",
            "-c",
            "#(nop) CMD [\"nginx\" \"-g\" \"daemon off;\"]"
        ],
        "Image": "107c338c1d31577c86670a0aa070ed903c9e00802838f9ffb8420a6acfb3dbaf",
        "Volumes": {
            "/var/cache/nginx": {}
        },
        "VolumeDriver": "",
        "WorkingDir": "",
        "Entrypoint": null,
        "NetworkDisabled": false,
        "MacAddress": "",
        "OnBuild": [],
        "Labels": {}
    },
    "DockerVersion": "1.6.0",
    "Author": "NGINX Docker Maintainers \"[email protected]\"",
    "Config": {
        "Hostname": "6c732c6044b7",
        "Domainname": "",
        "User": "",
        "AttachStdin": false,
        "AttachStdout": false,
        "AttachStderr": false,
        "PortSpecs": null,
        "ExposedPorts": {
            "443/tcp": {},
            "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.9.2-1~jessie"
        ],
        "Cmd": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "Image": "107c338c1d31577c86670a0aa070ed903c9e00802838f9ffb8420a6acfb3dbaf",
        "Volumes": {
            "/var/cache/nginx": {}
        },
        "VolumeDriver": "",
        "WorkingDir": "",
        "Entrypoint": null,
        "NetworkDisabled": false,
        "MacAddress": "",
        "OnBuild": [],
        "Labels": {}
    },
    "Architecture": "amd64",
    "Os": "linux",
    "Size": 0,
    "VirtualSize": 132841390
}
]
1

There are 1 best solutions below

0
On BEST ANSWER

Any docker command ( docker ps, docker stats...) is a call to the API. From the latest 1.7 doc https://docs.docker.com/reference/api/docker_remote_api_v1.17/ I see

Inspect a container

GET /containers/(id)/json

Return low-level information on the container id

Example request:

GET /containers/4fa6e0f0c678/json HTTP/1.1