Inspect container details in Docker
Let us learn how to find all of the details about Docker containers, from their current state, to their network settings and configuration.
Fresh bytes every Thursday. No spam, ever. Unsubscribe anytime.
Join 9,000+ developers and get three free video lessons every week.
Working with Docker containers can feel like a black box. Fortunately, there’s a command we can use to find out everything we need to know about them, from their current state, to their network settings and configuration.
We can use the docker inspect
command, passing to it any container name or id:
This returns a detailed JSON response which shows everything about your container:
The response can be overwhelming! Thankfully, Docker gives us access to a format flag (-f
) to extract just the details we need.
To use it, we’ll pass in some single quotes, followed by curly brackets. We can then reference properties names with a dot, then their name:
We can also access nested properties using this simple dot notation.
Here are a few common examples:
Docker also provides us access to some powerful template functions. Rather than using a dot and a reference to the property name, we will reference the name of the function.
For example, we can list out all environment variables using the range
function, coupled along with the println
function for line breaks:
Note that each of these template functions contain their own unique format, but some other functions include:
if/else
for conditional checkseq
for comparing valueslen
for getting array lengths
Pro tip: Start by running
docker inspect
without any flags to see the full JSON structure. Once you spot the data you need, use the format flag to extract just that info that you want.