Docker Community Forums

Share and learn in the Docker community.

Systemd/systemctl is not working in RHEL docker container

(Spsunil) #1

I am trying to install a spirit agent on RHEL docker container. I am using Dockerfile to build my own image.It is able to install the spirit agent but while starting the service using service command its saying
Failed to get D-Bus connection: Operation not permitted
Restarting spiritAgent (via systemctl): Failed to get D-Bus connection: Operation not permitted

I searched in google about this. I found that systemd is not present or installed.I tried to install systemd using following Dockerfile.This solution is given in following link.
FROM rhel7:latest
ENV container docker
RUN yum -y install systemd; yum clean all;
(cd /lib/systemd/system/; for i in ; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done);
rm -f /lib/systemd/system/
rm -f /etc/systemd/system/.wants/;
rm -f /lib/systemd/system/;
rm -f /lib/systemd/system/;
rm -f /lib/systemd/system/;
rm -f /lib/systemd/system/
rm -f /lib/systemd/system/*;
VOLUME [ \u201c/sys/fs/cgroup\u201d ]
CMD [\u201c/usr/sbin/init\u201d]

After creating the image using above Dockerfile, I used that image to install spirit agent. Still i am getting
a same error while starting the service. I tried many solutions suggested in google, but didn’t work.

I am using a RHEL 7.2 (Maipo) docker container image.

Can anyone look into this and help me out…

_Thank you

(David Maze) #2

Don’t do that. Just run the agent directly.

Systemd does a ton of things, and it’s not really appropriate to run inside a Docker container. (It wants to do things like cgroup management that don’t make sense; as the blog post you cited suggests, you need to force it to not run every single OS service; and you need to enable the dangerous --privileged option to do it.)

(Spsunil) #3

Hi David,
I agreed with your point, but i am trying to bring up some applications on
docker. They are already built applications. That requires a lot of changes
and takes time to change the required things for docker, so i need to check
first how it will go with docker. After trying out that solution also, i
was not able to use systemctl command to start the services what could be
the reason for that or is there anything else need to be installed. It
would be very useful if i get solution for this problem and it will be good

How to use systemd in a container?