Article 53AX6 not able to restrict cpu/ram of a docker container through systemd slices

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.latest?d=yIl2AUoC8zA latest?i=-H3zhp9Tfrc:rUmPq8aSr10:F7zBnMy latest?i=-H3zhp9Tfrc:rUmPq8aSr10:V_sGLiP latest?d=qj6IDK7rITs latest?i=-H3zhp9Tfrc:rUmPq8aSr10:gIN9vFw-H3zhp9Tfrc
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments