2

When I in a fedora container systemctl use, I get:

Failed to get D-Bus connection:: Unknown error -1

Does someone know how to fix this? Or can systemctl not be used in a docker container?

ericj
  • 2,138
  • 27
  • 44

3 Answers3

1

The systemctl command talks to systemd over a DBus connection. It is unlikely that you are running systemd in your container, so systemctl has nothing with which to talk.

While it is possible to run systemd in a container, doing so is often (but not always!) a sign that you need to rethink the architecture of your containers.

larsks
  • 277,717
  • 41
  • 399
  • 399
  • Indeed, systemd was not running. Now I understand the error! Why is it not good to use systemctl in containers? Because for example instead of `systemctl enable sshd`, I have to do `ssh-keygen -A` and then `/usr/sbin/sshd`. – ericj Feb 24 '15 at 19:54
  • Running a service manager inside a container hides service errors (e.g, "sshd crashed") from the host, which in turn makes it difficult for higher-level orchestration tools (like kubernetes, or even systemd on the host) to manage things. It also makes it more likely that someone will stuff a bunch of unrelated services into a container, which can ultimately make them more difficult to scale. – larsks Feb 24 '15 at 20:17
0

As already said, the standard systemctl needs SystemD. But for a command like "systemctl enable " or starting a service process one actually do that without a running SystemD.

The "systemctl enable" will essentially look into the sshd.service file for a "WantedBy=multi-user.target" clause and then it creates a symlink in /etc/systemd/system/multi-user.target.wants/. Similary, a "systemctl start" will look for the "ExecStart=/usr/bin/sshd" clause in the ssh.service file.

If you do not want look that up and run those parts manually, you could use my systemctl.py helper from the docker-systemctl-replacement which can do the interpretation of systemd service files for you.

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

I have fixed a similar issue, check this answer.

The main idea is to make /usr/sbin/init the first process inside the container.

Community
  • 1
  • 1
Anthony O.
  • 22,041
  • 18
  • 107
  • 163