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

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

问题描述

问题

似乎 systemd 无效或在Ubuntu Docker容器中可用.

设置

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

测试

如果我执行:

16,04 容器中的

systemctl status ssh

结果是错误无法连接到总线:没有这样的文件或目录

16.10 容器中,错误是: bash:systemctl:找不到命令.

如果执行 16.04 容器中找到哪个systemctl systemctl,但在 16.10 容器中找不到.

我发现/lib/systemd 存在.

我尝试通过以下方式安装systemd:

apt-get install systemd libpam-systemd systemd-ui

然后哪个systemctl 16.10

中找到systemctl

但是 systemctl status ssh 仍然显示错误无法连接到总线:没有这样的文件或目录

问题

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

为什么systemd在Ubuntu Docker容器中不处于活动状态?实例化容器时不使用systemd吗?

我没有找到有关Ubuntu/Ubuntu Docker映像的此主题的任何文档,只有关于从 Upstart systemd 的Ubuntu过渡的信息.是否有任何文档提供完整说明?

解决方案

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

如果它们包含systemd命令,则您会发现很多东西都无法使用,因为您的入口点替换了init.Systemd还利用了docker限制容器内部的cgroup,因为更改cgroup的能力可以使进程逃避容器的隔离.如果没有systemd在容器中以init的身份运行,则没有守护进程可以处理您的启动和停止命令.

Problem

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

Setup

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

Tests

If I execute:

systemctl status ssh in the 16,04 container

the result is the error Failed to connect to bus: No such file or directory

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

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

I have spotted that /lib/systemd exists.

I have tried installing systemd with:

apt-get install systemd libpam-systemd systemd-ui

Then which systemctl finds systemctl in 16.10

but systemctl status ssh still gives the error Failed to connect to bus: No such file or directory

Questions

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

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

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?

解决方案

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.

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天全站免登陆