Get cgroup in rootless container
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.
Oh, this is when running podman with --net host, when running without --net host i can just read /sys/fs/cgroup/memory.max
Carl Hörberg <carl.hoerberg@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
participants (2)
-
Carl Hörberg -
Giuseppe Scrivano