This Blog is to share our knowledge and expertise on Linux System Administration and VMware Administration

Thursday, January 18, 2018

Working with Docker Container - Returning low level information about a container

Returning low-level information about a container

While doing the debugging, automation, and so on, we will need the container configuration details. Docker provides the inspect command to get those easily.

To inspect a container/image, run the following command:
Syntax:
docker inspect [-f|--format="" CONTAINER|IMAGE [CONTAINER|IMAGE...]
We'll start a container and then inspect it:

root@Docker:~# docker run -id centos /bin/bash
c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256

root@Docker:~# docker inspect c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256

[
    {
        "Id": "c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256",
        "Created": "2018-01-02T12:18:18.232317934Z",
        "Path": "/bin/bash",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,

    .........
    .........
}]

Docker will look into the metadata and configuration for the given image or container and present it.

With the -f | --format option we can use the Go (programming language) template to get the specific information. The following command will give us an IP address of the container:

root@Docker:~# docker inspect --format='{{.NetworkSettings.IPAddress}}' c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256
172.17.0.4

The following command will give us an Hostname Path of the container:

root@Docker:~# docker inspect --format='{{.HostnamePath}}' c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256
/var/lib/docker/containers/c5f6ce3b5d2f82bb7a2bbc82b0b71bc2130ceb4caf163afbf5883cfbb150f256/hostname

For help with the docker inspect use --help

No comments:

Post a Comment