大网数据广告活动
服务器运维问答

failed to get D-Bus connection: Operation not permitted

· 52CE 我爱测

I'm trying to list services on my CentOS image running in Docker using systemctl list-units but I get this error message: Failed to get D-Bus connection: Operation not permitted Any suggestions what the problem might be?

问题原文

原帖链接 · Snowcrash · CC BY-SA 3.0

I'm trying to list services on my CentOS image running in Docker using

systemctl list-units  

but I get this error message:

Failed to get D-Bus connection: Operation not permitted

Any suggestions what the problem might be?

社区高分解答

原帖链接 · Murray Todd Williams · CC BY-SA 4.0

This isn't a direct answer to your question, but it may actually be more important, and I came across this realization as I was reading the other answers here.

I've had some experience migrating some complicated systems to Docker, and one of the significant realizations I've had is that you should ideally have one Docker container per application/service or "per daemon".

One very significant reason for this is that Docker will not cleanly shutdown services that you start with systemctl and in fact you may end up with the same sort of database corruptions that come from an unexpected power outage.

To dive into this a little deeper: when Docker issues a "stop" command to a container, it sends the SIGTERM signal only the one single process that was started with the CMD/ENTRYPOINT, not to all the services and daemons. So that one service has the warning to shutdown cleanly and all the others get unceremoniously terminated.

If you absolutely have to package two services in the same container (i.e. your application and a PostgreSQL database or something like that) then you need to have your CMD/ENTRYPOINT be a script that catches SIGTERM and then rebroadcasts it to those known services. It can be done, but if you have the opportunity, rethink your solution and try to break it into multiple containers.

An addendum

There's an interesting note/page on the Docker site about using supervisord if you absolutely need to have multiple services running in the same container.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-01-08)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。