Carl Hörberg <carl.hoerberg(a)gmail.com> writes:
When running a rootless container, how can one identify the cgroup
in
use from inside the container? /proc/self/cgroup is "0::/", but the
"real" cgroup is something like
"user-1000.slice/user@1000.service/user.slice/libpod-7126f828cd4389ca0a9e29a94e78af39c91f51f3f892a799cb7f3eeff067d1bd.scope/container".
One hacky way to find it out is to look at /run/.containerenv and get
the container id there, then to look for a directory in /sys/fs/cgroup
named libpod-$containerid.scope, but is there a more straight forward
one?
In the end I would like to be able to read "memory.max" and
"memory.current" in the cgroup dir.
you can get it from the `/proc/self/cgroup` file.
The cgroup v2 controller is the one prefixed with 0::.
$ podman run --rm --cgroupns host --net host -ti fedora sh
sh-5.1# cat /proc/self/cgroup
0::/user.slice/user-1000.slice/user@1000.service/user.slice/libpod-aff58243c495b7409a036930a467602d82226bc1e8f7c50eb3a8a439919b505c.scope/container
sh-5.1# cat
/sys/fs/cgroup//user.slice/user-1000.slice/user\@1000.service/user.slice/libpod-aff58243c495b7409a036930a467602d82226bc1e8f7c50eb3a8a439919b505c.scope/container/memory.max
max