Reputation: 21
I want to create a control group for managing resources related to some system management functions. Some of these run in docker containers. When I run these docker containers, I'd like to be able to specify the cgroup into which they're placed.
The 'docker run' command has an option, "--cgroup-parent", which hints that I should be able to do this. However. When I try to run the container using this option, I get errors.
This may be important: I'm using cgroups v2
So to start, I create a subdirectory in /sys/fs/cgroup/system.slice
mkdir /sys/fs/cgroup/system.slice/mygroup
cd /sys/fs/cgroup/system.slice/mygroup
echo +cpuset +cpu +io +memory +pids > cgroup.subtree_control
Then I attempt to run the docker container
docker run --cgroup-parent=/sys/fs/cgroup/system.slice/test -p 5201-5202:5201-5202 -v /root:/root -it --entrypoint "/bin/bash" docker-stress
At this point I get this response:
docker: Error response from daemon: cgroup-parent for systemd cgroup should be a valid slice named as "xxx.slice".
See 'docker run --help'.
This is using Ubuntu 18.04, docker version 20.10.07. Perhaps I don't understand the intent of the --cgroup-parent option. I've googled around for documentation and examples but I haven't had any luck. Does anyone know what I'm doing wrong here?
Upvotes: 1
Views: 2821
Reputation: 21
Well, chalk this one up to inexperience. The answer was in the error message. For v2 cgroups, cgroup parent names need to be named xxx.slice . For example, if we used a-b-c.slice, then the following cgroup hierarchy would be created:
/sys/fs/cgroup/a.slice/a-b.slice/a-b-c.slice
And the docker container cgroup would be created as docker-.scope under a-b-c.slice
Upvotes: 1