Sudo systemctl: failed to get d-bus connection

I wanted to add a user in my Dockerfile, but when I do systemctl doesn’t work correctly. Here’s a minimal example:

FROM resin/%%RESIN_MACHINE_NAME%%-debian:latest


RUN adduser --disabled-password --quiet --gecos “test” test
RUN usermod --append --groups sudo test
RUN printf “test:test” | chpasswd

USER test
WORKDIR /home/test

Then when I open the terminal and trying using systemctl, I get

test@d704d16:~$ sudo systemctl

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

Yet when I comment out all the new user lines, it works as expected.

Hi @spacelite

Can you tell us a bit more about your use case and why you need a non-root user? In general we recommend sticking with the root user unless the use case actually needs a non-root user to work.


@joe We are converting an existing Dockerfile over to resin, and that was one of the steps we had in the old file. It was there as a general security practice under the principle of least privilege. That said there’s nothing that specifically requires non-root to run, so I can just delete that if there’s no way around it.