【问题标题】:Failed to connect to bus: Host is down in ubuntu无法连接到总线:主机在 ubuntu 中已关闭
【发布时间】:2021-08-03 12:11:07
【问题描述】:

“sudo systemctl enable --now docker”在运行此命令时出现错误,例如“系统尚未使用 systemd 作为 init 系统 (PID 1) 启动。无法运行。 无法连接到总线:主机已关闭” 我该如何解决这个问题,而且我是 Ubuntu 命令的新手。

【问题讨论】:

  • 对于像 systemctlservice 这样的第一个近似命令在 Docker 中不起作用。您的图像需要配置为在前台运行主容器进程,而不是通过要求 init 系统在后台启动它。您能否编辑问题以包含您的 Dockerfile 或进一步演示该问题所需的任何其他代码工件?

标签: docker ubuntu virtualhost


【解决方案1】:

请参考Latest Docker Documentation;旧版本的 Docker 不能很好地运行。

诀窍是卸载 sudo apt-get remove docker docker.io containderd 等...并添加 docker GPG 密钥并设置存储库(记录在链接中)。然后安装sudo apt-get install docker-ce docker-ce-cli containerd.io

从 Ubuntu 安装中删除旧 docker 后,您可以转到 sudo service docker start 让 docker 守护程序在没有 systemctl 的情况下运行,并改用 service

【讨论】:

    【解决方案2】:

    我正在使用 ubuntu:20.04 图片。

    我在尝试在 ubuntu docker 容器中使用 systemctl 命令时遇到了同样的错误,因为 系统没有使用 systemd 作为 init 系统 (PID 1) 启动,正如错误所说为了解决这个问题,您需要使用它来启动容器

    docker run -ti -d ubuntu:20.04 "/sbin/init"
    

    其实运行容器会报错:

    I have solvedcontroller_1  | Failed to mount tmpfs at /run: Operation not permitted
    container_1 | Failed to mount tmpfs at /run/lock: Operation not permitted
    container_1 | [!!!!!!] Failed to mount API filesystems.
    container_1 | Freezing execution.
    

    默认情况下,容器无权访问任何设备,但带有“特权”标签的容器将其 root 权限授予主机系统上的所有设备,这些设备将允许访问容器以挂载 API 文件系统并解决问题。

    为了解决这个问题,你需要

    docker run -ti -d --privileged ubuntu:20.04 "/sbin/init"
    

    【讨论】:

      猜你喜欢
      • 2014-01-16
      • 2015-08-28
      • 2019-08-27
      • 2013-02-28
      • 2014-03-09
      • 2018-05-29
      • 2016-08-20
      • 1970-01-01
      • 2014-12-03
      相关资源
      最近更新 更多