Inspect a Docker container

In this article, we cover how to inspect a Docker container. We have seen how to list a docker container in previous article. But, what if we want detailed information about a container? Then, we can use inspect command.

Inspect a Docker Container

Use either Container ID or Container Name to inspect a Docker container. That part of data can be extracted through the following command –

docker container ls -a

where, -a option is used to list all containers irrespective of their current status.

After we have got the Container ID or Container Name, use the following syntax to get more information about (or, inspect) a Docker container –

docker container inspect <container-ID>

or,

docker container inspect <container-Name>

For instance,

docker container inspect ba017416ac98

or,

docker container inspect ABC

where, ba017416ac98 was the Container ID for us and Container name – ABC.

You would notice that the output contains lots of information. Some of us may be looking for a specific information from the output. In such a case, they would have to go through the entire output to extract that bit of information. Not something we recommend when we have got -f option to filter such data.

Following command can be used to extract information about the Config –

docker container inspect -f "{{json .Config}}" ba017416ac98 | jq .

If we want to go ahead without -f option then, we can also utilize –

docker container inspect ba017416ac98 | jq .[].Config

The output in both the cases would yield similar outcome.

Lastly, if we want to extract data about State, then replace Config with State in the above command. jq here is a command-line JSON processor.

In conclusion, we have covered how to inspect a Docker container here.

Similar Posts