skip to Main Content

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?

2

Answers


  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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search