<p>Situation: lots of heavy docker conainers that get hit periodically for a while, then stay unused for a longer period.</p>
<p>Wish: start the containers on demand (like systemd starts things through socket activation) and stop them after idling for given period. No <strong>visible</strong> downtime to end-user.</p>
<p>Options:</p>
<ul>
<li>Kubernetes has resource controllers which can scale replicas. I suppose it would be possible to keep the number of replicas on 0 and set it to 1 when needed, but how can one achieve that? The <a href="http://kubernetes.io/docs/user-guide/replication-controller/#scaling" rel="nofollow noreferrer">user guide</a> says there is something called an <em>auto-scaling control agent</em> but I don't see any further information on this. Is there a pluggable, programmable agent one can use to track requests and scale based on user-defined logic?</li>
<li>I don't see any solution in Docker Swarm, correct me if I'm wrong though.</li>
<li>Use a custom http server written in chosen language that will have access to the docker daemon. Before routing to correct place it would check for existence of container and ensure it is running. Downside - not a general solution, has to <strong>not</strong> be a container or have access to the daemon.</li>
<li>Use systemd as described <a href="https://developer.atlassian.com/blog/2015/03/docker-systemd-socket-activation/" rel="nofollow noreferrer">here</a>. Same downsides as above, i.e. not general and one has to handle networking tasks themselves (like finding the IP of the spawned container and feeding it into the server/proxy's configuration).</li>
</ul>
<p>Any ideas appreciated!</p>

xificurC
<p>You could use Kubernetes' built-in <a href="http://kubernetes.io/docs/user-guide/horizontal-pod-autoscaling/" rel="noreferrer">Horizonal Pod Autoscaling (HPA)</a> to scale up from 1 instance of each container to as many are needed to handle the load, but there's no built-in functionality for 0-to-1 scaling on receiving a request, and I'm not aware of any widely used solution.</p>
