Be Specific When Inspecting Docker Objects

Posted by Doug Toppin

Apr 12, 2017 7:42:00 AM Docker, Docker Containers

Here is an interesting tidbit having to do with docker inspect. The inspect function will return metadata associated with the object identifier that you include. That object identifier may be a container id, image id, name or other resource.

If you use a name as an argument instead of an image id or container id and you happen to have a container with the same name as an image, inspect might return the info for the one that you did not intend.

The way to be specific with your inspect request is to include the –type option which requires an argument of containerimage, volume or network.

The reason that you should include the type argument is demonstrated in the following example. 

The following will run a bash shell in an ubuntu container but will name it as python. 

docker run -it --name=python ubuntu bash

 

The following is how you might ask for an inspect on what you think is a python image.

docker inspect python

 

You might get back the metadata for the running container called python or you might get it for the image named python if there was one.

 

To be specific and indicate as to the resource the following refers to the image called python

docker inspect --type=image python 

 

This refers to the container called python.

docker inspect --type=container python

 

The importance of specificity is that it will alleviate the risk of getting back metadata of a different type than you expected which might impact an automation function such as a shell script. The side effects of getting back unexpected metadata might be that a script is unable to parse the response and cause an error.

 

Posted by Doug Toppin

Doug Toppin has been involved in software systems design and development in both the commercial and defense realms for more than 30 years. His experience includes small and large scale systems with high processing and availability requirements in a variety of applications.

Find me on:

    
Request a Complimentary Docker Consultation

An Open View

Vizuri Blog

Subscribing to our blog is a great way to stay up to date with the latest information from Vizuri, as well as our strategic partners. We focus on providing a range of content that is practically useful and relevant from both a technical and business perspective.

We promise to respect your privacy.

×