Validating Docker containers

Container Inspection

Historic Research

Several more test options exist in addition to those presented in Listing 1. For example, you can check the access rights of a file and the user and group IDs with Uid and Gid. The official documentation on GitHub [1] explains the currently available test set but only provided a brief reference when this issue went to press.

For your first steps, Google offers the Docker image, which essentially contains a Python interpreter. Matching tests can be found in a separate GitHub repository [3].

Parameters of the container-structure-test command-line tool have changed slightly in the past. Many examples online still refer to an older version. Even the official documentation on GitHub contains some broken sample commands.

Compared with older versions, you need to introduce the parameters with two hyphens and replace -test.v with the shorter test. Furthermore, the YAML file must be loaded explicitly with the --config parameter. In many obsolete examples, container-structure-test is also referred to as structure-test. The sample call that you frequently come across,

structure-test -test.v -image python_command_tests.yaml

thus needs to be converted to the following for the current 1.4.0 version:

container-structure-test test --image --config python_command_tests.yaml

In case of doubt, you can call

container-structure-test help

to reveal the valid parameters.


CST lets developers and admins validate containers extremely quickly. In most cases, you do not even need to start the containers. Thanks to the short YAML (or JSON) notation, the tests are quick and easy to enter, without a long learning curve.

However, the simple structure of the test descriptions does tend to limit your options. To find out whether version 5.7 or newer of MySQL is installed involves some contortions. Furthermore, CST is designed to test containers and images before they are used and not during operation. If you need to carry out extensive tests on live containers, you might want take a look at another product, such as Testinfra [4].

The Author

Tim Schürmann is a freelance computer scientist and author. Besides books, Tim has published various articles in magazines and on websites.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy ADMIN Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

comments powered by Disqus
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs

Support Our Work

ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

Learn More”>


		<div class=