tocker is a plugin for testinfra that allows developers to test docker images
pip install tocker
Set your environment variables to connect to docker engine:
export DOCKER_HOST=unix:///var/run/docker.sock
If docker engine runs a different host, set the following:
export DOCKER_TLS_VERIFY=1
export DOCKER_HOST=tcp://ip:port
export DOCKER_CERT_PATH=/path/to/certs
If you're using docker-machine, you can simply run:
eval $(docker-machine env myenv)
- Create a 
Dockerfile - Create a 
test.pyin the same directory - Add 
IMAGE_TAGto test.py. E.g:mycorp/nginx:1.9.12 - Write your tests (find out more about how to use different modules from testinfra docs)
 - Run 
testinfra test.py(-s -vfor verbose mode) - Watch your tests fail
 - Edit your 
Dockerfileuntil the tests pass - When you're happy 
docker pushthe image 
tockerbuilds an image fromDockerfile- The image will be tagged with 
IMAGE_TAG - When the image is successfully built, a new container is created
 - Tests are run against the created container with 
docker exec - The container is destroyed at the end of all test cases
 tockeruses docker build cache so the consecutive runs are fast- The resulting image is not removed
 
If you're looking to add a new module, please contribute to testinfra.
If it's more specific to Docker, you can add additional fixtures under tocker/fixtures.py. Pull requests are welcome.
