dotcloud/docker — pull request #4469 by alexlarsson (2014-03-05 13:42:12+00:00)
Title: Implement foreground execution mode

This implements a "-f" switch for docker run, so you can do something like:
docker run -f fedora echo hello

This will run the echo command as a direct decendant of the docker client process, rather than a child of the docker daemon. It will also pass stdin/out/err directly from the docker client to the container.

This is particularly interesting when you're integrating docker containers with some other form of execution manager, such as systemd. Systemd can via cgroups and the normal process hierarchy completely control the container processes, and implement things like restart-on-exit, stdout logging, cgroup containment, integration with systemd unit (so you can e.g. systemctl stop the container).

The way it works is by calling out to the docker daemon which fully sets up the container, but uses a custom execdriver, that when started calls into the docker client via golang rpc calls. The client then creates a real execdriver and proxies the request to that, which starts the container. The client then stays around monitoring the container and exits with the right exit status, as well as telling the docker daamon that the container exited.

Additionally the client accepts a few other RPC calls so that the other daemon side execdriver requests (docker stop, docker ps, docker top, etc) still works. We also implement Restore by reconnecting to the client, so the docker containers survive the daamon restarting.