Docker Image Sanity Checks
If you’re building Docker images as part of a build process / CI pipeline, here’s an easy way to verify your image isn’t broken.
RUN set -x && [ "$(some command)" = "expected output" ]
For example, in this Terraform image, I’ve added this statement at the bottom of the Dockerfile:
RUN set -x && [ "$(terraform version)" = "Terraform v0.7.4" ]
If the output does not match, the docker build process will return a rather rude error, The command ‘/bin/sh -c set -x && [ “$(terraform version)” = “Terraform v0.7.4”]’ returned a non-zero code: 1, and will exit.
Obviously, this approach isn’t practical when you need to test a variety of use cases, but if you’re wrapping other executables and need a simple sanity check (and you’re lazy — like me), this works.