Joey Yi Zhao
Joey Yi Zhao

Reputation: 42634

How to restart a docker container if it runs for a period of time

I am implementing a service which create Docker container for short time execution task. The service receives requests from clients and create a Docker container to run the request. Then get the response from the container and send it back to clients.

I want to limit the execution time of the Docker container for example, kill the container if it runs more than 20 minutes. Is there a configuration I can set on the container to stop in 20 minutes? Or do I have to manually calculate the execution time in my service? What is the better way to achieve that?

Upvotes: 0

Views: 1134

Answers (1)

agrizzli
agrizzli

Reputation: 31

Docker itself does not provide such an option. Please refer to a long proposal issue on GutHub

You will need a combination of timeout utility and docker kill in aftermath to really kill orphaned container.

Upvotes: 2

Related Questions