I have a process on a cron job that starts every 30 minutes. The process starts a docker container with a given image name. Sometimes the process running in the docker container gets bogged down and then I end up with several docker containers running; the more I have running the more it gets bogged down. Of course there are underlying issues that are causing this (they're getting worked on too). For THIS question I want to know "Is there a way to kill all of the running docker containers with a given image name EXCEPT for the last container that started running?"
I looked at this SO question and it shows how to kill all of them. Is there a way to exclude the most recent container?
I'm working in Linux and I'd be willing to write a shell script that could be called to do this when needed.