0

I am building an image with docker file,in my docker file i execute a script.In script,There are some commands like:

systemctl start postgresql-9.6.service
systemctl disable NetworkManager

And when i execute docker build, it goes error:

Failed to get D-Bus connection: Operation not permitted

Image based on centos. I try to use base centos image which supports systemd(solita/centos-systemd ),but it did not work.

Any ideas?

zysaaa
  • 1,777
  • 2
  • 8
  • 19
  • Hi zysaaa, what do you want to achieve? Only in very few cases, it is recommended to start a service via systemctl inside docker. Please provide additional information regarding your use case – ckaserer Nov 18 '19 at 09:21
  • Thanks for your comment,i am very new to docker.And I want to set up the environment needed to run the project in my dockerfile, such as some configuration of the database ,enable sshd service and so on,and after `docker build`, the image I get will have everything I need. Shouldn't these operations be performed in dockerfile?@ClemensKaserer – zysaaa Nov 18 '19 at 09:28
  • possible duplicate of https://stackoverflow.com/questions/50393525/failed-to-get-d-bus-connection-operation-not-permitted – Here_2_learn Nov 18 '19 at 09:32
  • Hi here_2_learn, good point, but I would not see this as a duplicate. The issue here seems to stem more from trying to work with containers like you would with VMs. – ckaserer Nov 18 '19 at 09:41
  • @zysaaa if any of the answers solved your issue please accept the appropriate answer to share the resolution with the community. If not please provide further information – ckaserer Dec 23 '19 at 08:49

2 Answers2

1

Moving Conversation from comments to answer:

Clemens: Hi zysaaa, what do you want to achieve? Only in very few cases, it is recommended to start a service via systemctl inside docker. Please provide additional information regarding your use case

zysaaa: Thanks for your comment,i am very new to docker.And I want to set up the environment needed to run the project in my dockerfile, such as some configuration of the database ,enable sshd service and so on,and after docker build, the image I get will have everything I need. Shouldn't these operations be performed in dockerfile?@ClemensKaserer

Clemens: Well no^^. A docker image should have a single purpose, e.g. run your postgres database. That means in your container you only want to run that single process (postgres) and nothing else. So no entire OS with all it's subprocesses. That is one aspect that makes container technology so powerful. You do not need to run the entire OS, just the process that you need. For postgres, in particular, I recommend that you use the official image and go from there. By taking a look at the Dockerfile associated with the image you will already learn quite a lot about how you should work with containers ;)


Here the link to the postgres image on dockerhub

and the associated dockerfile for the image with the tag: latest

If you got anything that you would like explained, just comment on the answer and I will extend it within the answer.

ckaserer
  • 4,827
  • 3
  • 18
  • 33
1

On Centos7 all services are started and stopped through 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. Simply because there is no systemd in a container.

The docker-systemctl-replacement script can be used to avoid the situation. And the docker-systemctl-images examples do already contain a postgres variant.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19