47

I'm trying to install ambari 2.6 on a docker centos7 image but in the the ambari setup step and exactly while initializing the postgresql db I receive this error:

Failed to get D-Bus connection: Operation not permitted

I've got this error every time I try to run a service on my docker image.

I tried every solution in the net but nothing worked yet.

Does any one have an idea how to resolve this ?

Thank you in advance

Cuga
  • 17,668
  • 31
  • 111
  • 166
fadhloun anis
  • 525
  • 1
  • 6
  • 13

4 Answers4

41

Use this command

docker run -d -it --privileged {Image ID} /usr/sbin/init

And access root in container

systemctl start httpd.service

This should work!

Drew Dormann
  • 59,987
  • 13
  • 123
  • 180
  • 3
    Doesn't work any longer I guess: I get this error: `C:\Program Files\Docker\Docker\Resources\bin\docker.exe: Error response from daemon: OCI runtime create failed: container_linux.go:348: star ting container process caused "exec: \"C:/Program Files/Git/usr/sbin/init\": stat C:/Program Files/Git/usr/sbin/init: no such file or direct ory": unknown. ` – samayo Sep 12 '18 at 02:04
  • 2
    ContainerId should be ImageId – Happier Mar 20 '20 at 07:54
  • 3
    As a noob, I was not sure how to "access root in container": `docker exec -it CONTAINER bash` – Bjorn Aug 13 '20 at 10:12
  • 1
    this work as a temporary solution since we can't run container everytime in `privileged` mode – Bruce wayne - The Geek Killer Sep 23 '21 at 04:59
  • Hello, your solution does not work for me. I replicate this using a `centos:7` image (from the official repo instead of Docker Hub), also I access as a root, without luck. I solve this using a replacement for `systemctl`, but I was trying to solve it without it. – Franco Gil Apr 06 '23 at 19:22
14

On Centos7 all the services are started and stopped throught the systemd daemon. The systemctl command will simply try to talk to the daemon by using a d-bus channel - and that's where the message comes from.

Instead of running a container in priviledged mode (so it is not really contained) you could also try out the docker-systemctl-replacement to avoid the situation.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19
  • Can it not talk to the deamon the normal way, for example unix sockets? Or just running it once to start the process and then that's all? – jgmjgm Oct 21 '19 at 14:36
  • To "just run the processes and detach" ... that's the replacement script does. The systemd daemon works completely different in that the services are children so that it can monitor their existance and the systemd will also know about the exitcode of them - the default Restart=on-failure depends on that. // doing with unix sockets, well it's simply not how it is implemented. Not my choice. – Guido U. Draheim Oct 22 '19 at 11:15
  • 1
    If it's not possible it's a major missing feature of systemd. It's a very important capability. I work a lot with making my own process managers. It's really not hard to make them run something once then exit or wrap that in a mini process or run resident and manage or supervise a collection or processes. It's the kind of thing that might make a good question on its own. There isn't a good reason why. You tell systemd how to start things but that sounds like it coupled with other things so you can't just start a thing which is a standard design flop. – jgmjgm Oct 22 '19 at 22:53
14

To elaborate on @Guido's answer, what worked for me was copying systemctl.py from here and placing it in the same directory as my Dockerfile, and then adding the following to my Dockerfile:

COPY systemctl.py /usr/bin/systemctl
RUN chmod a+x /usr/bin/systemctl

E.g., this allowed me to start an sshd service like so:

service sshd start
asherbret
  • 5,439
  • 4
  • 38
  • 58
  • 2
    this solution worked for me. I builded the docker image using this `systemctl.py` and it worked. I didn't know anything about what logic written in that file, but it allows us to use systemctl in the docker image – Bruce wayne - The Geek Killer Sep 23 '21 at 05:02
-3

Run this command:

docker run -it -p 1001:25 --name postfix1 --privileged -d   --cap-add=SYS_ADMIN -v /sys/fs/cgroup:/sys/fs/cgroup:ro postfix
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
CHARITRA JAIN
  • 49
  • 1
  • 3