I'm trying to list services on my CentOS image running in Docker using
systemctl list-units
but I get this error message:
Failed to get D-Bus connection: Operation not permitted
Any suggestions what the problem might be?
centosdockersystemctlsystemd
I'm trying to list services on my CentOS image running in Docker using
systemctl list-units
but I get this error message:
Failed to get D-Bus connection: Operation not permitted
Any suggestions what the problem might be?
Best Answer
My guess is that you're running a
non-privileged
container. systemd requires CAP_SYS_ADMIN capability but Docker drops that capability in the non privileged containers, in order to add more security.systemd also requires RO access to the cgroup file system within a container. You can add it with
–v /sys/fs/cgroup:/sys/fs/cgroup:ro
So, here a few steps on how to run CentOS with systemd inside a Docker container:
Build it -
docker build -t centos7-systemd - < mydockerfile
Run a container with
docker run --rm --privileged -ti -e container=docker -v /sys/fs/cgroup:/sys/fs/cgroup centos7-systemd /usr/sbin/init
You should have systemd in your container