无法在 ubuntu docker 容器上使用 systemd [英] Not able to use systemd on ubuntu docker container

查看:146
本文介绍了无法在 ubuntu docker 容器上使用 systemd的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题

似乎 systemd 在 Ubuntu Docker 容器中未激活或不可用.

It seems systemd is not active or available in Ubuntu Docker containers.

设置

我正在从 ubuntu:16.04ubuntu:16.10 镜像运行 Docker 容器.

I'm running Docker containers from the ubuntu:16.04 and ubuntu:16.10 images.

测试

如果我执行:

systemctl status ssh 16,04 容器

结果是错误Failed to connect to bus: No such file or directory

16.10 容器中,错误是:bash: systemctl: command not found.

In the 16.10 container the error is: bash: systemctl: command not found.

如果我执行 which systemctl systemctl 在 16.04 容器中但不在 16.10 容器中.

If I do which systemctl systemctl is found in the 16.04 container but not in the 16.10 container.

我发现 /lib/systemd 存在.

我尝试使用以下方法安装 systemd:

I have tried installing systemd with:

apt-get install systemd libpam-systemd systemd-ui

然后which systemctl16.10

但是systemctl status ssh 仍然报错Failed to connect to bus: No such file or directory

问题

如何激活 systemd 和 systemctl 以在 Ubuntu Docker 镜像中使用?

How can systemd and systemctl be activated for use in Ubuntu Docker images?

为什么 systemd 在 Ubuntu Docker 容器中不活跃?实例化容器时不使用systemd吗?

Why is systemd not active in Ubuntu Docker containers? Is systemd not used in instantiating the container?

我没有找到任何关于 Ubuntu/Ubuntu Docker 镜像的文档,只有关于从 Upstartsystemd 的 Ubuntu 转换的信息.是否有任何文档给出了完整的解释?

I have failed to find any documentation on this topic for Ubuntu / Ubuntu Docker images, only information on the Ubuntu transition from Upstart to systemd. Is there any documentation giving a full explanation?

推荐答案

这是设计使然.Docker 应该在容器的前台运行一个进程,它将在容器的 pid 命名空间中作为 PID 1 生成.Docker 是为进程隔离而设计的,而不是为操作系统虚拟化而设计的,因此容器内没有其他操作系统进程和守护进程(如 systemd、cron、syslog 等),只有您运行的入口点或命令.

This is by design. Docker should be running a process in the foreground in your container and it will be spawned as PID 1 within the container's pid namespace. Docker is designed for process isolation, not for OS virtualization, so there are no other OS processes and daemons running inside the container (like systemd, cron, syslog, etc), only your entrypoint or command you run.

如果它们包含 systemd 命令,您会发现很多东西都不起作用,因为您的入口点替换了 init.Systemd 还使用 docker 限制在容器内部的 cgroups,因为更改 cgroups 的能力可以允许进程摆脱容器的隔离.如果 systemd 在您的容器内不作为 init 运行,则没有守护进程来处理您的启动和停止命令.

If they included systemd commands, you'd find a lot of things not working since your entrypoint replaces init. Systemd also makes use to cgroups which docker restricts inside of containers since the ability to change cgroups could allow a process to escape the container's isolation. Without systemd running as init inside your container, there's no daemon to process your start and stop commands.

这篇关于无法在 ubuntu docker 容器上使用 systemd的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆