[SOLVED] not able to restrict cpu/ram of a docker container through systemd slices
Linux - ContainersThis forum is for the discussion of all topics relating to Linux containers. Docker, LXC, LXD, runC, containerd, CoreOS, Kubernetes, Mesos, rkt, and all other Linux container platforms are welcome.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
not able to restrict cpu/ram of a docker container through systemd slices
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)
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/python
Then 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 don't think you're actually addressing the problem that I want to solve. I'm talking about limiting resources per container groups, not indivdually. That is to say, two or more containers should not use more than 20% of the cpu and 200MB of RAM.
Individual cpu and ram limitations work without any issues, I've already tried that. The point is to create a sort of profile based on systemd slices.
For instance, this answer is exactly what I'm looking for (but it doesn't work): https://stackoverflow.com/questions/...host-resources
I'm not saying that it's correct, but that's the idea where I'm starting from.
I've recreated the exact environmental conditions of as that of the instructor: Centos 7 and docker installed through the official centos repositories (instead of the docker repositories).
Code:
[root@centos7 etc]# docker version
Client:
Version: 1.13.1
API version: 1.26
Package version: docker-1.13.1-161.git64e9980.el7_8.x86_64
Go version: go1.10.3
Git commit: 64e9980/1.13.1
Built: Tue Apr 28 14:43:01 2020
OS/Arch: linux/amd64
Server:
Version: 1.13.1
API version: 1.26 (minimum version 1.12)
Package version: docker-1.13.1-161.git64e9980.el7_8.x86_64
Go version: go1.10.3
Git commit: 64e9980/1.13.1
Built: Tue Apr 28 14:43:01 2020
OS/Arch: linux/amd64
Experimental: false
Quote:
[root@centos7 etc]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
And this works as expected. Of course, that's hardly satisfying. What happens if I want to use a newer version of docker? It obviously works differently.
No, I haven't. And I'm not sure if this is a bug. After all it works when using the docker version of the offical centos repository, so the one officially supported by Red Hat (but not when using the official docker repositories).
In the first case yum installs great many other dependencies, which might be relevant in some way:
When using the docker repository, it install much fewer things, but I think there are different technologies being used (it might not be using containerd in the first case, if that's meaningful in any way).
These are the dependencies of docker from the docker repository:
Quote:
containerd.io x86_64 1.2.13-3.1.el7 docker-ce-stable 23 M
docker-ce x86_64 3:19.03.8-3.el7 docker-ce-stable 25 M
docker-ce-cli x86_64 1:19.03.8-3.el7 docker-ce-stable 40 M
Installing for dependencies:
audit-libs-python x86_64 2.8.5-4.el7 base 76 k
checkpolicy x86_64 2.5-8.el7 base 295 k
container-selinux noarch 2:2.119.1-1.c57a6f9.el7 extras 40 k
libcgroup x86_64 0.41-21.el7 base 66 k
libsemanage-python x86_64 2.5-14.el7 base 113 k
policycoreutils-python x86_64 2.5-34.el7 base 457 k
python-IPy noarch 0.75-6.el7 base 32 k
setools-libs x86_64 3.3.8-4.el7 base 620 k
docker version (centos):
Version: 1.13.1
API version: 1.26
actually docker was never compatible with itself and is growing rapidly. 1.13 is at about 4 years old (jan 2017), so 19.03 definitely may contain something new, which was not taken into account in that CentOS release (officially). Probably something was renamed (a feature, config, option, whatever), something was restructured [definitely] (even the versioning concept was changed since then). Probably you need to set cgroup driver https://stackoverflow.com/questions/...ver-to-systemd.
Excellent! This is exactly what I needed. It works like a charm, although I configured it slightly different than the guy on stackoverflow.
I first copied docker.service from /lib/systemd/system/ to /etc/systemd/system, knowing that this is how you can keep the systemd script persistent after upgrading docker and I simply added the "--exec-opt native.cgroupdriver=systemd" to the ExecStart like so:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.