在docker中启用systemd

发布时间 2023-08-15 18:19:50作者: 武平宁

参考:Docker systemd进程管理器

以 amazn linux 2023 测试

# cat amazonlinux-systemd

docker run -tid -p 2222:22 --hostname amazonlinux-systemd --name amazonlinux-systemd \
  --entrypoint=/usr/lib/systemd/systemd \
  --env container=docker \
  --mount type=bind,source=/sys/fs/cgroup,target=/sys/fs/cgroup \
  --mount type=bind,source=/sys/fs/fuse,target=/sys/fs/fuse \
  --mount type=tmpfs,destination=/tmp \
  --mount type=tmpfs,destination=/run \
  --mount type=tmpfs,destination=/run/lock \
  amazonlinux-systemd --log-level=info --unit=sysinit.target

测试成功。

如果不加那几个目录的mount,但是增加--privileged=true,测试结果是可以启动,但是关闭容器后重启会失败。

报错日志:

Failed to open libbpf, cgroup BPF features disabled: Operation not supported

增加了mount的启动日志中相关的部分如下:

Not running with unified cgroup hierarchy, disabling cgroup BPF features.

区别在于是否systemd是否需要cgroup BPF features,操作系统一般是没有安装这个模块的。