在docker的lcentos7中出现Failed to get D-Bus connection: Operation not permitted
时间: 2023-11-09 13:02:23 浏览: 45
这个问题通常是由于docker容器中没有运行systemd导致的。可以尝试在启动容器时加上--privileged参数,或者在Dockerfile中添加以下内容:
```
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
rm -f /lib/systemd/system/multi-user.target.wants/*;\
rm -f /etc/systemd/system/*.wants/*;\
rm -f /lib/systemd/system/local-fs.target.wants/*; \
rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
rm -f /lib/systemd/system/basic.target.wants/*;\
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ "/sys/fs/cgroup" ]
CMD ["/usr/sbin/init"]
```
相关问题
docker报错 Failed to get D-Bus connection: Operation not permitted
当你在使用Docker时,可能会遇到"Failed to get D-Bus connection: Operation not permitted"的错误。这个错误通常是由于Docker容器内部无法访问宿主机的D-Bus系统总线导致的。
D-Bus是Linux系统中的一个进程间通信机制,用于在不同进程之间传递消息。Docker容器默认是以隔离的方式运行的,因此无法直接访问宿主机的D-Bus系统总线。
要解决这个问题,你可以尝试以下几种方法:
1. 使用特权模式(privileged mode):在运行Docker容器时,使用--privileged参数来开启特权模式。这将允许容器内部访问宿主机的D-Bus系统总线。但是要注意,特权模式可能会带来安全风险,因此需要谨慎使用。
2. 挂载宿主机的D-Bus套接字:在运行Docker容器时,使用-v参数将宿主机的D-Bus套接字文件挂载到容器内部的相应位置。例如:
```
docker run -v /var/run/dbus:/var/run/dbus ...
```
这样容器内部就可以通过挂载的路径访问宿主机的D-Bus系统总线。
3. 使用host网络模式:在运行Docker容器时,使用--network=host参数来使用宿主机的网络命名空间。这样容器将直接使用宿主机的网络配置,包括D-Bus系统总线。
以上是解决"Docker报错Failed to get D-Bus connection: Operation not permitted"的几种方法。你可以根据具体情况选择适合的方法来解决问题。
在systemctl start sshd.service中出现Failed to get D-Bus connection: Operation not permitted 怎么办
引用中提到的错误信息"Failed to get D-Bus connection: Operation not permitted"通常是由于缺乏特权或权限不足导致的。引用中解释了这个问题可能出现在使用Docker容器时的原因。Docker容器是一个独立的主进程,而不是一个完整的操作系统,它默认以普通用户权限运行,没有特权访问Linux内核。因此,当在容器中使用systemd的systemctl命令时,会出现权限不足的问题。
解决这个问题的方法是确保在容器中以特权模式运行或使用适当的特权选项。可以尝试在docker run命令中添加"--privileged"选项来授予容器特权权限。这样容器就能够访问Linux内核并执行systemctl命令。例如:
```
docker run --privileged -d <image_name>
```
另外,还可以考虑将服务运行在容器中的前台,而不是使用systemctl命令。这样可以避免使用systemd和特权权限,更符合容器的设计原则。
请注意,具体的解决方法可能因为使用的操作系统和容器环境而有所不同。建议参考引用中提供的参考文章来获取更多关于解决该问题的信息和方法。<span class="em">1</span><span class="em">2</span>
#### 引用[.reference_title]
- *1* *2* [容器里用systemctl运行服务报错:Failed to get D-Bus connection: Operation not permitted(解决方法)](https://blog.csdn.net/Dontla/article/details/125628230)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]