docker: make sure to cleanup containers before force exit

Observed containers were being left over on the host machine when
docker tests were terminated mid way. Due to this, host machine was not
able to run anymore containers after a certain threshold of running
containers and eventually runs out of available memory. Fix this issue
by always cleaning the containers when exiting from the tests.

Change-Id: I14056ba1e883a40fbd4251d1565da1ee5b102770
diff --git a/test/docker/ b/test/docker/
index ef6f771..5b1894d 100755
--- a/test/docker/
+++ b/test/docker/
@@ -85,8 +85,7 @@
     usage "$MISSING, did you forget --events-plugin-jar?"
 [ -n "$GERRIT_WAR" ] && cp -f -- "$GERRIT_WAR" "$ARTIFACTS/gerrit.war"
-progress "Building docker images" build_images
-run_events_plugin_tests ; RESULT=$?
-exit "$RESULT"
+( trap cleanup EXIT SIGTERM
+    progress "Building docker images" build_images
+    run_events_plugin_tests