Docker Inspect

Docker inspect command is very useful to provide detailed 
information about any container. It provides all information
related to image, volume etc. without login into container.You
can find out each details you needed.
# docker inspect container	(Put container's actual name or ID of the container you want to inspect)

# docker inspect ubuntu:latest	(To inspect a Docker image, use the image's name or ID as an argument)

# docker inspect volume		(To inspect a Docker volume, use the volume's name as an argument)

# docker inspect my_network	(To inspect a Docker network, use the network's name as an argument)
You can also use output formatting to inspect docker which 
returns a JSON representation of the object. You can format the
output using tools like jq or by using the --format option to
extract specific fields or properties.

docker inspect --format='{{.Name}}' container
(This command will display only the container's name)
# docker inspect container volume network	(You can inspect multiple things as well)
Now if you want to save inspect output in json. You can use 
below command.
# docker inspect my_container > container_info.json
Let's see some examples with its output for a running container 
named *web1*.

The below command will give you all details of a container.
# docker inspect web1

root@docker:~# docker inspect web1
[
    {
        "Id": "a3fdbd0159f7ba057df46a7b3d328f1ecce829c149a4c33ea2896b106a20ea26",
        "Created": "2023-11-10T05:28:50.455118697Z",
        "Path": "/docker-entrypoint.sh",
        "Args": [
            "nginx",
            "-g",
            "daemon off;"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 1942,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-11-10T05:28:50.876777879Z",
            "FinishedAt": "0001-01-01T00:00:00Z"

-----
-----
-----
-----
You can replace web1 with volume, network etc. if you want to 
know details of other things.

If you want to know the creation date of container then use
below command.
# docker inspect -f '{{.Created}}' web1


root@docker:~# docker inspect -f '{{.Created}}' web1
2023-11-10T05:28:50.455118697Z
root@docker:~#
Inspecting the label's of a container.
# docker inspect -f '{{.Config.Labels}}' web1


root@docker:~# docker inspect -f '{{.Config.Labels}}' web1
map[maintainer:NGINX Docker Maintainers <docker-maint@nginx.com>]
root@docker:~#
Find put IP address of container.
# docker inspect -f '{{.NetworkSettings.IPAddress}}' web1


root@docker:~# docker inspect -f '{{.NetworkSettings.IPAddress}}' web1
172.17.0.2
root@docker:~#
Inspect environment variables of a container.
# docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' web1


root@docker:~# docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' web1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
NGINX_VERSION=1.25.3
NJS_VERSION=0.8.2
PKG_RELEASE=1~bookworm
Inspect parent image of a container.
# docker inspect -f '{{.Config.Image}}' ubuntu


root@docker:~# docker inspect -f '{{.Config.Image}}' ubuntu
sha256:5cc7f35b23e8f38a4b42c98905260503375a3a09b30da1d333cf42f4bed58f29
root@docker:~#
Find out exposed port for a container.
# docker inspect -f '{{.Config.ExposedPorts}}' web1


root@docker:~# docker inspect -f '{{.Config.ExposedPorts}}' web1
map[80/tcp:{}]
Find out current status of a container.
# docker inspect -f '{{.State.Status}}' web1


root@docker:~# docker inspect -f '{{.State.Status}}' web1
running
Inspect logs of the container.
# docker inspect -f '{{.LogPath}}' web1


root@docker:~# docker inspect -f '{{.LogPath}}' web1
/var/lib/docker/containers/a3fdbd0159f7ba057df46a7b3d328f1ecce829c149a4c33ea2896b106a20ea26/a3fdbd0159f7ba057df46a7b3d328f1ecce829c149a4c33ea2896b106a20ea26-json.log
Inspect subnet of a network.
# docker inspect -f '{{.IPAM.Config}}' frontend


root@docker:~# docker inspect -f '{{.IPAM.Config}}' frontend
[{192.168.10.0/24   map[]}]
Let's find out the entry point of image. 
# docker inspect -f '{{.Config.Entrypoint}}' nginx:latest


root@docker:~# docker inspect -f '{{.Config.Entrypoint}}' nginx:latest
[/docker-entrypoint.sh]
Find out Image ID.
# docker inspect -f '{{.Id}}' nginx:latest


root@docker:~# docker inspect -f '{{.Id}}' nginx:latest
sha256:c20060033e06f882b0fbe2db7d974d72e0887a3be5e554efdb0dcf8d53512647

Leave a Reply

Your email address will not be published. Required fields are marked *