Docker doesn't support this (yet).
Here is a possible workaround. Warning: this is a very hackish. I don't really recommend using that in production, but it gives you an idea of what is involved.
We will use a Mesos hook (or a tool like Docker Spotter) to trigger automatic actions when containers are started.
We will also use a separate, manually created cgroup with the appropriate CPU share allocation.
When the tool detects that one of the two containers was just started, it moves all its processes to this special cgroup. Since all child processes are created in the control group of their parent, all future processes will also be in that cgroup.
Note, however, that there is a potential race condition: if new processes are created in those containers while you move the existing processes from the original cgroup to the "static" one, the new processes might not be moved automatically. You would probably have to rescan the tasks
file multiple times to make sure you moved everything.
A better implementation would be in Docker itself; maybe by allowing the creation of "container containers" (containers which don't run processes but are just there to group other containers) and then put a container under another one. Or, alternatively, a syntax similar to --volumes-from
, but for resources. That would allow to start a container but instruct Docker to create the cgroups under an existing container.