Failed to get D-Bus connection: Operation not permitted in systemd enabled centos

I planned to install Openldap in centos. So i followed the official image of systemd centos from dockerhub.
I used the following Dockerfile to create the image.

FROM centos/systemd

RUN yum -y install openldap openldap-servers; yum clean all; systemctl start slapd; systemctl enable slapd; systemctl systemctl status slapd

RUN yum -y install net-tools

EXPOSE 389

CMD ["/usr/sbin/init"]

But when i build it, i encountered Failed to get D-Bus connection: Operation not permitted. How to fix this?

1 Like

I have the same issue too. Follow there is a simple Dockerfile to reproduce such issue:

FROM centos/systemd
CMD ["/usr/sbin/init"]  

Then I build the container with:

docker build --rm -t test  .

And then I run my container so:

docker run -it --privileged --name test -v /sys/fs/cgroup:/sys/fs/cgroup:ro test bash

[root@1aca3d8d6b6c /]# systemctl status
Failed to get D-Bus connection: Operation not permitted

How can I fix?