Docker Community Forums

Share and learn in the Docker community.

Auto stop/remove container after X hours?


(Tomes12) #1

Hi,

Been researching but can’t find anything - I was wondering if there is such an option for “docker run” that allows me to set a parameter for “self terminate” container after some time.

Example I would like to create a container that will automatically stop and terminate after X hours without additional intervention after it has been run/created.

Hope I’m making sense.

Please let me know if something like this possible and how?

Thank you,


(Bryce Ryan) #2

So far as I know, there’s nothing in the “docker run” command that will explicitly terminate a container after a period of time. You’d likely need to take care of that with the logic running inside the container, or to use a wrapper that started the container, waited for the allotted time, then terminated the container. A creative solution might involve use of the --health-<> related options, e.g. --health-interval, --health-cmd, --health-retries, --health-start-period, and --health-timeout


(Tomes12) #3

Thank you for taking the time to answer.

At least I which direction to continue.