Reading a container's metadata
While doing debugging, automation, and so on, we will need the container's configuration details. Docker provides the container inspect
command to get those easily.
Getting ready
Ensure that the Docker daemon is running on the host and can be connected through the Docker client.
How to do it...
To inspect a container, run the following command:
$ docker container inspect [OPTIONS] CONTAINER [CONTAINER...]
We'll start a container and then inspect it, like so:
$ ID=$(docker container run -d -i ubuntu /bin/bash)$ docker container inspect $ID

How it works...
Docker will look into the metadata and configuration for the given container and present it in JSON format. Using tools like jq
, this JSON formatted output can be further post-processed.
There's more...
With the -f | --format
option, we can use the Go (programming language) template to get this specific information. The following command will give us an IP address for the container:
$ docker container inspect \ ...