I am relatively new to Docker but I am looking for a way to replace shell commands that are used to build an image and execute a container. We are using Jenkins for pipelining and implementing it using Groovy. In our deploy groovy file, there are two stages that (1) build the image using a Dockerfile and (2) execute the container from that image. In the second stage, the shell script checks all the running containers and if there are more than a certain amount of containers already running, it will wait a few minutes for other containers to be purged.
This is just a brief overview but I just wanted to see if anyone knew of a way to replace these shell scripts with something better, possibly through the use of other containers or plugins.