not able to restrict cpu/ram of a docker container through systemd slices
by vincix from LinuxQuestions.org on (#53AX6)
Hi,
I'm trying to restrict the resources of a docker container through a systemd slice, as follows:
I've created the systemd slice (/etc/systemd/system/my_limits.slice)
Code:[Unit]
Description=my slice for docker resources
Before=slices.target
[Slice]
CPUAccounting=true
CPUQuota=20%
MemoryAccounting=true
MemoryLimit=200MThen ran: systemctl daemon-reload
And afterwards ran the container that is supposed to be governed by the cgroup slice:
Code:docker run --rm -it --cgroup-parent=my_limits.slice docker.io/pythonThen I'm running some python code to stress the CPU. Unfortunately the CPU rises to 100%, instead of being limited to 20%.
I'm not sure what I'm doing wrong.
Using --cpus="0.2" does work as expected.
P.S. Is there any way I can confirm that the slice I've created is somehow acknowledged by systemd?
systemctl -t slice --all does not show my own slice, but I'm guessing it might be showing only the "essential"/system ones?
I'm running docker 19.03.8 in an Ubuntu 18.04 VM.


I'm trying to restrict the resources of a docker container through a systemd slice, as follows:
I've created the systemd slice (/etc/systemd/system/my_limits.slice)
Code:[Unit]
Description=my slice for docker resources
Before=slices.target
[Slice]
CPUAccounting=true
CPUQuota=20%
MemoryAccounting=true
MemoryLimit=200MThen ran: systemctl daemon-reload
And afterwards ran the container that is supposed to be governed by the cgroup slice:
Code:docker run --rm -it --cgroup-parent=my_limits.slice docker.io/pythonThen I'm running some python code to stress the CPU. Unfortunately the CPU rises to 100%, instead of being limited to 20%.
I'm not sure what I'm doing wrong.
Using --cpus="0.2" does work as expected.
P.S. Is there any way I can confirm that the slice I've created is somehow acknowledged by systemd?
systemctl -t slice --all does not show my own slice, but I'm guessing it might be showing only the "essential"/system ones?
I'm running docker 19.03.8 in an Ubuntu 18.04 VM.