当 Docker 镜像以终端模式启动时,如下所示:
docker run --mount type=tmpfs,destination=/run --mount type=tmpfs,destination=/run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro --entrypoint '/bin/bash' -it jrei/systemd-debian:10
然后手动输入:
exec /lib/systemd/systemd
systemd 显示初始化日志,如下所示:
ACL +XZ +LZ4 +SECCOMP +BLKID +ELFUTILS +KMOD -IDN2 +IDN -PCRE2 default-hierarchy=hybrid)
Detected virtualization docker.
Detected architecture x86-64.
Welcome to Debian GNU/Linux 10 (buster)!
Set hostname to <e9366e98a874>.
File /lib/systemd/system/systemd-journald.service:12 configures an IP firewall (IPAddressDeny=any), but the local system does not support BPF/cgroup based firewalling.
Proceeding WITHOUT firewalling in effect! (This warning is only shown for the first loaded unit using IP firewalling.)
[ OK ] Reached target Slices.
[ OK ] Started Dispatch Password Requests to Console Directory Watch.
[ OK ] Reached target Swap.
[ OK ] Reached target Local File Systems.
Starting Create System Users...
[ OK ] Reached target Local Encrypted Volumes.
[ OK ] Reached target Paths.
....
当 Docker 镜像在没有终端模式下启动时,例如:
docker run --mount type=tmpfs,destination=/run --mount type=tmpfs,destination=/run/lock -v /sys/fs/cgroup:/sys/fs/cgroup:ro --entrypoint '/bin/bash' jrei/systemd-debian:10 -c "exec /lib/systemd/systemd"
systemd 不显示任何输出。我无法使用-t
或-i
开关,因为 docker 命令在我正在使用的命令执行器中是硬连线的。应该如何修改上面的命令以使用输出启动 systemd 并且仍然使用 PID 1(exec
直接从入口 shell 启动)但没有-t
Docker tty 开关?