LewisGaul / systemd-containers

Tests demonstrating what does/doesn't work when trying to run systemd inside a container
1 stars 0 forks source link

systemd in a docker container with cgroups v2 #1

Closed aki-k closed 10 months ago

aki-k commented 12 months ago

Hi,

I read your e-mail to systemd-devel but thought to respond to you here and not in the mailing list.

I run systemd in a docker container like this:

root@2cc4ddb64cc7:~# cat /proc/1/cgroup 0::/init.scope

root@2cc4ddb64cc7:~# ls -la /sys/fs/cgroup/ total 0 drwxr-xr-x 5 root nogroup 0 Sep 29 12:34 . drwxr-xr-x 10 nobody nogroup 0 Sep 29 12:34 .. -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.controllers -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.events -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.freeze --w------- 1 nobody nogroup 0 Sep 29 12:34 cgroup.kill -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.max.depth -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.max.descendants -rw-r--r-- 1 root nogroup 0 Sep 29 12:34 cgroup.procs -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.stat -rw-r--r-- 1 root nogroup 0 Sep 29 12:34 cgroup.subtree_control -rw-r--r-- 1 root nogroup 0 Sep 29 12:34 cgroup.threads -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cgroup.type -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.idle -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.max -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.max.burst -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.stat -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.weight -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpu.weight.nice -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpuset.cpus -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpuset.cpus.effective -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpuset.cpus.partition -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpuset.mems -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 cpuset.mems.effective -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.current -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.events -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.events.local -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.rsvd.current -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.1GB.rsvd.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.current -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.events -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.events.local -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.rsvd.current -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 hugetlb.2MB.rsvd.max drwxr-xr-x 2 root root 0 Sep 29 12:34 init.scope -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 io.stat -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.current -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.events -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.events.local -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.high -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.low -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.max -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.min -rw-r--r-- 1 root nogroup 0 Sep 29 12:34 memory.oom.group --w------- 1 root nogroup 0 Sep 29 12:34 memory.reclaim -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.stat -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.swap.current -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.swap.events -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.swap.high -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 memory.swap.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 misc.current -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 misc.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 pids.current -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 pids.events -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 pids.max -r--r--r-- 1 nobody nogroup 0 Sep 29 12:34 rdma.current -rw-r--r-- 1 nobody nogroup 0 Sep 29 12:34 rdma.max drwxr-xr-x 10 root root 0 Sep 29 12:34 system.slice drwxr-xr-x 3 root root 0 Sep 29 12:34 user.slice



I didn't run your tests but as I see it systemd in the container works fine.
LewisGaul commented 12 months ago

Thanks, that's interesting. I assume this is effectively the same as using rootless Podman?

Couple of questions:

aki-k commented 12 months ago

I assume this is effectively the same as using rootless Podman?

I'm using the docker daemon dockerd.

What does findmnt /sys/fs/cgroup show inside the container?

# findmnt /sys/fs/cgroup
TARGET         SOURCE FSTYPE  OPTIONS
/sys/fs/cgroup cgroup cgroup2 rw,nosuid,nodev,noexec,relatime

what's the contents of /sys/fs/cgroup/cgroup.subtree_control?

# cat /sys/fs/cgroup/cgroup.subtree_control
memory pids
aki-k commented 11 months ago

I tried running the same Dockerfile with podman but got this error:

https://github.com/containers/crun/issues/1308

aki-k commented 11 months ago

The problem I had with a systemd enabled podman container was resolved by an update to crun (Fedora 37)

pradyparanjpe commented 10 months ago

I guess I've this problem with gitlab-ce images after upgrading from Fedora 38 to Fedora 39(Beta).

crun: chmod `run/motd.dynamic`: Operation not supported: OCI runtime error

I got redirected from https://github.com/containers/crun/issues/1308.

LewisGaul commented 10 months ago

@aki-k This is interesting, thanks for the input on using Docker with cgroups v2 for systemd containers, I might try it out one day. In actual fact I'm more interested in cgroups v1 currently (partly because of the additional challenges), where I think the examples in this repo are more relevant.

I'll close the issue because people seem to be getting redirected and commenting here from an entirely unrelated issue.