dotcloud/docker — pull request #1077 by mhennings (2013-06-30 15:55:43+00:00)
Title: Introduce sessions as a clean way to handle cleanup of temp. containers

Introduce sessions as a clean way to handle cleanup of temporary containers.

Why?
============================================================================
When working with docker, especially the builder a lot of temporary containers
are required.

In a production environment keeping old containers is important too.

So if there was a way to distinct between short lived containers that are
tempoary and those that need to be kept an automatic clean up routine could
take care of the containers that are not interesting any more.

How?
===========================================================================

Before work start a new session. This is optional, if you do not create a
session the behavior of docker is the same as before.

DOCKER_SESSION=`docker session`

In this example we create a simple session, that has no name and will not be
automatically cleaned.

On the docker commands run and build you can specify the session, to attach
the newly created container to the session.

docker run -s $DOCKER_SESSION ....
docker build -s $DOCKER_SESSION ....

Afterwards the sessions can be listed with

docker sessions

or if you want to see the containers

docker sessions -c

The filter options from docker ps work too.

To clean up you simply call

docker clean

Sessions will be cleaned only if a timeout was set, and there is no active
container, and no container has been active within the time of the timeout. If
the session itself is younger as the timeout it wont be collected.

If you do not need to automatically clean up, you still can use sessions as a
grouping function.

To delete a session explicitly call

docker rms

=======================================================

Please let me know what you think. I am aware of the fact that this feature might be more and less usefull for different users.