为了在 centos 容器中使用 systemctl,需要两个条件:
1、需要包含 Volume(卷) /sys/fs/cgroup
如果不包含这个卷,执行 systemctl 会报错:
Couldn't find an alternative telinit implementation to spawn。
2、需要在 run 时加 --privileged,运行在特权模式,容器内的 root 用户不再是普通用户,拥有真正的 root 权限。
如果不加此选项,那么在启动时,挂载卷的时候会报错:
Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.