If you are using docker I don't understand why are you leaving you hub up and running.
Check out their hub page: https://github.com/SeleniumHQ/docker-selenium/tree/master/Hub
Hub launch: docker run -d -p 4444:4444 --name selenium-hub selenium/hub
Nodes launch:
$ docker run -d --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-chrome
$ docker run -d --link selenium-hub:hub -v /dev/shm:/dev/shm selenium/node-firefox
I would write a pipeline and define my hub image and node images which I bring up at the beginning of the test session and remove the images at the end of the session.
try {
hubimage
nodeimage
runtests
} catch(anything) {
throw anything;
} finally {
sh "docker rmi \$(docker inspect --format='{{range .RepoTags}} {{.}} {{end}}' ${hubimage});"
sh "docker rmi \$(docker inspect --format='{{range .RepoTags}} {{.}} {{end}}' ${nodeimage});"
}
See more information about pipelines on https://jenkins.io/doc/book/pipeline/.