Docker Community Forums

Share and learn in the Docker community.

How to stop a container automatyically when it's idle

dockercloud

(R1sknt) #1

Hello, everyone I have a project where a container starts on demand but I want it to be stopped when it’s idle automatically.

basically, the idea is that if you stop using the container for 15 min it will be automatically stopped


(David Maze) #2

Why? How can you tell if it’s “idle”? How would you restart it?

If you can answer those questions, then whatever monitoring agent decides it’s idle can cause the process to exit (if it’s inside the container) or docker stop (if it’s outside the container). But the “if you stop using the container” question isn’t well-defined in a way that there’s any automated tooling for it.


(R1sknt) #3

why? cuz the container has more than one process independent from each other but necessary to have them both as per my scenario so if the main work exited one process will be stopped but the other would still work and the container wouldn’t stop

how can tell it’s idle? that’s what I’m looking for. maybe based on the processes activity.
I don’t know exactly how but if someone has a solution please share with me.

restarting is not a problem for me I will make a small program to do that for me