翻译自 https://georgik.rocks/how-to-start-d-bus-in-docker-container/
很多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