0

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?

halfer
  • 19,824
  • 17
  • 99
  • 186
Joey Yi Zhao
  • 37,514
  • 71
  • 268
  • 523
  • Possible duplicate of [How to limit \`docker run\` execution time?](https://stackoverflow.com/questions/48299352/how-to-limit-docker-run-execution-time) – Mathias Apr 07 '19 at 09:40
  • You could add a `timeout` command to the image `CMD` and then add a restart policy to your Docker config. – halfer Apr 07 '19 at 18:15

1 Answers1

2

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.

Matthijs
  • 2,483
  • 5
  • 22
  • 33
agrizzli
  • 31
  • 2