• Welcome to Journal web site.

我是 PHP 程序员

- 开发无止境 -

Next
Prev

System has not been booted with systemd as init system (PID 1). Can‘t operate. Failed to connect to

Data: 2020-10-01 02:21:11Form: JournalClick: 17

问题

docker内进行systemctl等命令时,出现错误。

System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down

解决方法

docker启动方式需要变化。启动时添加 --privileged=true/sbin/init
后面/bin/bash需要替换为/sbin/init

即由此方式:

 docker run -tid --name test centos  /bin/bash

变更为:

 docker run -tid --name test --privileged=true  centos  /sbin/init
 
完整参数说明:
 docker run -v /tmp/:/tmp --privileged --cap-add SYS_ADMIN -e container=docker -it --name=centos -d --restart=always centos /usr/sbin/init
  • -v /tmp/:/tmp:挂载宿主机的一个目录,冒号":"前面的目录是宿主机目录,后面的目录是容器内目录。

  • --privileged: 指定容器是否是特权容器。

  • --cap-add SYS_ADMIN: 添加系统的权限,不然系统很多功能都用不了的。

  • -e container=docker:设置容器的类型。

  • -it: 启动互动模式。

  • /usr/sbin/init:初始容器里的CENTOS,用于启动dbus-daemon。

 
已经创建的docker容器修改方式查看【相关文章】
Name:
<提交>