Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Run systemctl on Debian 11 Docker gets "Failed to connect to bus"

If none of the specific sub-forums seem right for your thread, ask here.
Post Reply
Message
Author
fernandocesarpinto
Posts: 25
Joined: 2021-05-13 14:44

Run systemctl on Debian 11 Docker gets "Failed to connect to bus"

#1 Post by fernandocesarpinto »

I just built an image from Dockerhub and installed systemd:

Code: Select all

FROM debian:bullseye
ENV ANSIBLE_USER=ansible SUDO_GROUP=sudo DEPLOY_GROUP=deployer
RUN apt-get install -y --no-install-recommends sudo systemd systemd-sysv

# Add non-privileged user
RUN set -xe \
    && groupadd -r ${ANSIBLE_USER} \
    && groupadd -r ${DEPLOY_GROUP} \
    && useradd -m -g ${ANSIBLE_USER} ${ANSIBLE_USER} \
    && usermod -aG ${SUDO_GROUP} ${ANSIBLE_USER} \
    && usermod -aG ${DEPLOY_GROUP} ${ANSIBLE_USER} \
    && sed -i "/^%${SUDO_GROUP}/s/ALL\$/NOPASSWD:ALL/g" /etc/sudoers
VOLUME ["/sys/fs/cgroup"]
CMD ["/lib/systemd/systemd"]
When I run systemctl inside the container I get:

Code: Select all

Failed to connect to bus: No such file or directory
If I run `/lib/systemd/systemd` I get:

Code: Select all

Trying to run as user instance, but $XDG_RUNTIME_DIR is not set.
I found this error many times on Google but no solution, I see it may be related to the change of v1 to v2 of cgroup, but I don't have good knowledge of cgroup. Can something hint me at a way to fix this?

Aki
Global Moderator
Global Moderator
Posts: 2816
Joined: 2014-07-20 18:12
Location: Europe
Has thanked: 68 times
Been thanked: 382 times

Re: Run systemctl on Debian 11 Docker gets "Failed to connect to bus"

#2 Post by Aki »

Hello,

In the previous message, it appears that you are installing systemd in a debian installation. This is quite unusual, because systemd is the default init system and it's a important installation requirement: systemd is usually installed by default in a standard installation (even if different init systems are available), This let me suppose that you are trying to replicate the behavior of debian installer using "ansible", but in this case you have to get rid of all basic requirements in terms of minimum functionality of the operating system. A basic installation of a debian file system can be done, for example, using the command debootstrap [0], but before booting it.

Systemd uses dbus service [1] as a inter process communication channel [2]: have you installed the dbus package ?

[0] https://manpages.debian.org/bullseye/de ... .8.en.html
[1] https://packages.debian.org/bullseye/dbus
[2] https://www.freedesktop.org/software/sy ... temd1.html
⢀⣴⠾⠻⢶⣦⠀
⣾⠁⢠⠒⠀⣿⡁ Debian - The universal operating system
⢿⡄⠘⠷⠚⠋⠀ https://www.debian.org
⠈⠳⣄⠀

fernandocesarpinto
Posts: 25
Joined: 2021-05-13 14:44

Re: Run systemctl on Debian 11 Docker gets "Failed to connect to bus"

#3 Post by fernandocesarpinto »

Aki wrote: 2021-09-08 06:09 Hello,

In the previous message, it appears that you are installing systemd in a debian installation. This is quite unusual, because systemd is the default init system and it's a important installation requirement: systemd is usually installed by default in a standard installation (even if different init systems are available), This let me suppose that you are trying to replicate the behavior of debian installer using "ansible", but in this case you have to get rid of all basic requirements in terms of minimum functionality of the operating system. A basic installation of a debian file system can be done, for example, using the command debootstrap [0], but before booting it.

Systemd uses dbus service [1] as a inter process communication channel [2]: have you installed the dbus package ?

[0] https://manpages.debian.org/bullseye/de ... .8.en.html
[1] https://packages.debian.org/bullseye/dbus
[2] https://www.freedesktop.org/software/sy ... temd1.html
No, I did not install it. If I try I get same error repeatedly:

Code: Select all

# apt install dbus
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libdbus-1-3
Suggested packages:
  default-dbus-session-bus | dbus-session-bus
The following NEW packages will be installed:
  dbus libdbus-1-3
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 458 kB of archives.
After this operation, 1123 kB of additional disk space will be used.
Do you want to continue? [Y/n] 
Get:1 http://deb.debian.org/debian bullseye/main amd64 libdbus-1-3 amd64 1.12.20-2 [219 kB]
Get:2 http://deb.debian.org/debian bullseye/main amd64 dbus amd64 1.12.20-2 [239 kB]
Fetched 458 kB in 0s (4081 kB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libdbus-1-3:amd64.
(Reading database ... 15946 files and directories currently installed.)
Preparing to unpack .../libdbus-1-3_1.12.20-2_amd64.deb ...
Unpacking libdbus-1-3:amd64 (1.12.20-2) ...
Selecting previously unselected package dbus.
Preparing to unpack .../dbus_1.12.20-2_amd64.deb ...
Unpacking dbus (1.12.20-2) ...
Setting up libdbus-1-3:amd64 (1.12.20-2) ...
Setting up dbus (1.12.20-2) ...
Failed to connect to bus: No such file or directory
Failed to connect to bus: No such file or directory
invoke-rc.d: could not determine current runlevel
invoke-rc.d: policy-rc.d denied execution of start.
Failed to connect to bus: No such file or directory
/usr/sbin/policy-rc.d returned 101, not running 'start dbus.service dbus.socket'
Processing triggers for libc-bin (2.31-13) ...

Post Reply