TransWikia.com

systemctl failed to connect to bus - docker ubuntu:16.04 container

Ask Ubuntu Asked by Duncan Gravill on November 1, 2021

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?

8 Answers

Just start the dbus service:

/etc/init.d/dbus start

Answered by exud on November 1, 2021

If you're getting this error in the Windows Subsystem for Linux (WSL), I've found it's because Docker is unsupported. This is due to lack of cgroups and other prerequisites.

Answered by ijustlovemath on November 1, 2021

Try this:

docker run -ti -d --privileged=true images_docker  "/sbin/init"

or

docker run -ti -d --privileged=true images_docker

will be same result.

Here I get from the doc of Docker:

By default, Docker containers are “unprivileged” and cannot, for example, run a Docker daemon inside a Docker container. This is because by default a container is not allowed to access any devices, but a “privileged” container is given access to all devices (see the documentation on cgroups devices).

When the operator executes docker run --privileged, Docker will enable access to all devices on the host as well as set some configuration in AppArmor or SELinux to allow the container nearly all the same access to the host as processes running outside containers on the host. Additional information about running with --privileged is available on the Docker Blog.

Answered by sonjaya sonjaya on November 1, 2021

I was getting the exact same error and then I run it successfully with sudo

sudo systemctl status ssh

Answered by Saif on November 1, 2021

Inside docker container, I think you can update-rc.d if you are still struggling with systemd. I tried with update-rd.c and it works.

Answered by NEERAJ SWARNKAR on November 1, 2021

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.

Answered by user228505 on November 1, 2021

You may not be running systemd, which is the default implementation of init on 16.04. If you upgraded from 14.04, you are most likely still running upstart, and the result of running the systemctl command is the output you got.

See my answer at systemctl : comand not found 16.04 server for more.

Answered by Hugh Buntu on November 1, 2021

Others have reported a similar problem. Start up the terminal and type:

$ env

Do you see an environment variable like this?

XDG_RUNTIME_DIR=/run/user/`id -u`

Where id -u is enclosed in backticks not single quotes. This variable is reinterpreted into a number usually 1000 for regular users and 0 for super user (sudo).

If the environment variable XDG_RUNTIME_DIR does not exist you need to create it. The full discussion is in launchpad systemd answers.

Answered by WinEunuuchs2Unix on November 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP