Docker – systemctl Failed to Connect to Bus in Docker Ubuntu 16.04 Container


I'm trying to use the systemctl command in a ubuntu:16.04 docker container. I'm running the following command…

systemctl status ssh

However I'm getting the error…

Failed to connect to bus: No such file or directory

Why is this not working? Is this related to Ubuntu running in a docker container? How can I get systemctl to work correctly?

Best Answer

I assume you start your docker container with something like

docker run -t -i ubuntu:16.04 /bin/bash

The problem now is that your init process PID 1 is /bin/bash, not systemd. Confirm with ps aux.

In addition to that you are missing dbus with would be the way to communicate. This is where your error message is coming from. But as your PID 1 is not systemd, it will not help to install dbus.

Best would be to re-think the way you plan to use docker. Do not rely on systemd as a process manager but have the docker container run your desired application in the foreground.

Related Question