2025年4月16日 星期三 乙巳(蛇)年 正月十七 设为首页 加入收藏
rss
您当前的位置:首页 > 计算机 > 云技术 > Docker

如何在 Docker 容器中启动 D-Bus

时间:12-14来源:作者:点击数:20

很多 Linux 应用需要用到 D-Bus,但它在 Docker 容器中默认并不存在,当你尝试启动这类应用时,你会收到一个错误信息:

  • D-Bus library appears to be incorrectly set up; failed to read machine uuid: Failed to open "/var/lib/dbus/machine-id": No such file or directory
  • See the manual page for dbus-uuidgen to correct this issue.
  • D-Bus not built with -rdynamic so unable to print a backtrace
  • Aborted

首先你需要通过下面命令生成缺失的 machine-id(译者注:我一般是直接在容器启动时挂载 host 上的 machine-id):

  • dbus-uuidgen > /var/lib/dbus/machine-id

这样以来,即使 DBus 守护进程没有启动,应用也能启动,要在容器中启动 D-Bus 守护进程,你需要运行下面命令

  • mkdir -p /var/run/dbus
  • dbus-daemon --config-file=/usr/share/dbus-1/system.conf --print-address

在 Centos 上则改为:

  • dbus-daemon --config-file=/etc/dbus-1/system.conf --print-address

现在守护进程运行起来了,你的应用也能用了,输出的结果类似于下面这样:

  • unix:path=/var/run/dbus/system_bus_socket,guid=9cfabcc6f66027251e092e955d09e707
方便获取更多学习、工作、生活信息请关注本站微信公众号城东书院 微信服务号城东书院 微信订阅号
推荐内容
相关内容
栏目更新
栏目热门
本栏推荐