在docker容器中执行systemctl命令时,报错:Failed to get D-Bus connection: Operation not permitted的具体解决方法,首先我们得进入这个报错问题的docker容器,然后按下面的步骤操作:
1、备份systemctl文件,出于习惯先备份,当然,如果不想备份也没什么
mv /usr/bin/systemctl /usr/bin/systemctl.old
2、重新下载systemctl文件,这一步才是解决问题的关键
curl https://raw.githubusercontent.com/gdraheim/docker-systemctl-replacement/master/files/docker/systemctl.py > /usr/bin/systemctl
3、给下载的systemctl文件重新赋予可执行权限,当然你可以先查看下这个文件是否已有可执行权限,如果有了的话可以不需要再次赋予可执行权限
chmod +x /usr/bin/systemctl
如此,再次在容器中执行systemctl相关就可以正常执行了,同时相关联的service命令也可以正常执行了
