Shell Docker中不带-t开关的系统输出

Shell Docker中不带-t开关的系统输出,shell,docker,systemd,Shell,Docker,Systemd,在终端模式下启动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 docker run --mount type=tmpfs,destination=/run --mou

在终端模式下启动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
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"
然后手动输入:

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.
....

systemd不显示任何输出。我不能使用
-t
-I
开关,因为docker命令是在我正在使用的命令执行器中硬连线的。如何修改上面的命令以启动带输出的系统,并且仍然使用PID 1(直接从入口外壳使用
exec
),但不使用
-t
Docker tty开关?

我的建议是不惜一切代价避免在Docker中使用系统。例如,如果查看示例输出中的
OK
内容,则不希望Docker中有这些内容。一般做法是只在容器中运行某个应用程序,而不使用init系统,或者使用一些极其简单的工具,如
tini
。我需要它来测试经常使用systemctl的Ansible角色。我已经完成了所有工作,唯一剩下的是如何模拟
-t
交换机。虚拟机可能更适合此用例,因为Docker容器通常只运行一个进程,没有类似于sshd或其自己的网络堆栈的东西。我知道这是不典型的。通过使用
-t
开关启动systemd,我使其完全工作,包括sshd服务。我只需要知道如何创建一个假tty,以便systemd认为它是由
-t
开关启动的,并显示其输出。我的建议是不惜一切代价避免systemd进入Docker。例如,如果查看示例输出中的
OK
内容,则不希望Docker中有这些内容。一般做法是只在容器中运行某个应用程序,而不使用init系统,或者使用一些极其简单的工具,如
tini
。我需要它来测试经常使用systemctl的Ansible角色。我已经完成了所有工作,唯一剩下的是如何模拟
-t
交换机。虚拟机可能更适合此用例,因为Docker容器通常只运行一个进程,没有类似于sshd或其自己的网络堆栈的东西。我知道这是不典型的。通过使用
-t
开关启动systemd,我使其完全工作,包括sshd服务。我只需要知道如何创建一个伪tty,以便systemd认为它是由
-t
开关启动的,并显示其输出。