问题
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?
回答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.
回答2:
I have fixed a similar issue, check this answer.
The main idea is to make /usr/sbin/init
the first process inside the container.
回答3:
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.
来源:https://stackoverflow.com/questions/28662021/in-fedora-container-systemctl-gives-failed-to-get-d-bus-connection