Answers: <p>I'm not aware of any straightforward way to do that, without also running a different container to act as a middleware of sorts. You might want to look at one of the "Serverless" platforms. If your use case will fit that model, many of the docker/swarm/kubernetes serverless tools do what you're asking, but again, you're running other container(s) to manage it. I'd suggest starting with a glance at the <a href="https://docs.openfaas.com/" rel="nofollow noreferrer">OpenFAAS docs</a> to see if it'll work for you. </p>
  
Answers: CC BY-SA 4.0
Answers: 2019-01-02T08:55:58.847Z
Answers: 2019-01-02T08:55:58.847Z
Answers: Zeb
Body: <p>Is there any way by which I can set a lifetime for a container after that much of time it should be stopped automatically and only awake when someone send a request. I wanted something like <strong>Preemptable Google Compute engine</strong> instance or <strong>Heroku free Dyno</strong> which sleeps after 1 hr of inactivity and awake again when a request is send to that instance. </p>
  
  <p><strong>Note</strong>: I have docker compose project so I want to set the life time for one service which depends on other services also. I have a traefik container runs separately beside the docker-compose project which handles the request and sends to containers. So is there something like request_post_hook which can start that stopped docker-compose container when receive any request ? </p>
  
Comments: CC BY-SA 4.0
Comments: 2019-01-02T13:27:59.943Z
Comments: This reads like you are trying to make something like AWS Lambda, Google Cloud Functions or Azure Functions. It’s not clear why you need the service to be stopped. We would assume so that you don’t have to pay for it. In which case using the “official solution” for pay-as-you-go computation at google would be a good solution. Note that such solutions are actually expensive in terms of the actual cost of the compute but cheap in the sense that you can use tiny amounts only on demand. Any large service that would run the processing logic continuously wouldn’t save money.
Comments: simbo1905
Tags: <docker><docker-compose><docker-swarm><google-compute-engine>
Title: How to create a preemptable docker container?
UserDisplayName: SkyRar
ThreadText: # How to create a preemptable docker container?
  
  (Asked by: username_0 on 2018-12-24)
  
  Is there any way by which I can set a lifetime for a container after that much of time it should be stopped automatically and only awake when someone send a request. I wanted something like **Preemptable Google Compute engine** instance or **Heroku free Dyno** which sleeps after 1 hr of inactivity and awake again when a request is send to that instance.
  
  **Note**: I have docker compose project so I want to set the life time for one service which depends on other services also. I have a traefik container runs separately beside the docker-compose project which handles the request and sends to containers. So is there something like request\_post\_hook which can start that stopped docker-compose container when receive any request ?
  
  **Tags:** docker, docker-compose, docker-swarm, google-compute-engine
  
  > **Comments:**
  > **username_1**: This reads like you are trying to make something like AWS Lambda, Google Cloud Functions or Azure Functions. It’s not clear why you need the service to be stopped. We would assume so that you don’t have to pay for it. In which case using the “official solution” for pay-as-you-go computation at google would be a good solution. Note that such solutions are actually expensive in terms of the actual cost of the compute but cheap in the sense that you can use tiny amounts only on demand. Any large service that would run the processing logic continuously wouldn’t save money.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2019-01-02. Score: 1
  
  I'm not aware of any straightforward way to do that, without also running a different container to act as a middleware of sorts. You might want to look at one of the "Serverless" platforms. If your use case will fit that model, many of the docker/swarm/kubernetes serverless tools do what you're asking, but again, you're running other container(s) to manage it. I'd suggest starting with a glance at the [OpenFAAS docs](https://docs.openfaas.com/) to see if it'll work for you.
  
  
  ---
  
  