Let’s say you have a docker container that you run periodically, and it runs fine most of the time, but in some rare cases, it hangs. This can be very annoying, and it might take some time to find the root cause of the problem.
In the meantime, it would be great if the container would be terminated automatically after exceeding a user-defined maximum runtime.
To solve this problem, you can use the following Python script (don’t forget to change image_name and max_minutes to your environment):