Docker: Failed to get D-Bus connection, Operation not permitted

博客介绍了在docker容器的Centos7中执行systemctl命令报错的解决方案。使用docker run特权模式,即docker run -d -it --privileged ContainerId /usr/sbin/init可解决。若用docker-compose,在docker-compose.yml中添加privileged: true和command: /usr/sbin/init即可。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在docker容器中Centos7执行 

systemctl --type=service --all

systemctl命令时,报上面错

解决方案:

用docker run 特权模式

docker run -d -it --privileged ContainerId /usr/sbin/init

就能解决,如果用docker-compos,只需在docker-compose.yml中加上相应的即可:

version: '3'
services:
  centos:
    image: centos:7
    container_name: centos
    tty: true
    privileged: true
    ports:
      - 8885:21007
      - 8886:21008
      - 3308:3306
      - 5435:5432
      - 9012:9011
      - "8122:22"
      - "8121:21"
    volumes:
      - /home/hello/workspace:/home/hello/workspace
    restart: always
    command: /usr/sbin/init
 

主要是privileged: true和command: /usr/sbin/init 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值