Systemctl status is not working in my Docker container

Hi, if you go to docker hub of centos7 release you are using there is instruction on how to run the centos with systemctl enabled.In short:

  1. Create a dockerfile and paste:

FROM centos:7
MAINTAINER “you” your@email.here
ENV container docker
RUN (cd /lib/systemd/system/sysinit.target.wants/; for i in ; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done);
rm -f /lib/systemd/system/multi-user.target.wants/
;
rm -f /etc/systemd/system/.wants/;
rm -f /lib/systemd/system/local-fs.target.wants/;
rm -f /lib/systemd/system/sockets.target.wants/udev;
rm -f /lib/systemd/system/sockets.target.wants/initctl;
rm -f /lib/systemd/system/basic.target.wants/
;
rm -f /lib/systemd/system/anaconda.target.wants/*;
VOLUME [ “/sys/fs/cgroup” ]
CMD ["/usr/sbin/init"]

Then build the container using in the dir you have created the file (be sure no other files are inside, as they will be taken into the context and may cause troubles :wink: )

docker build --rm -t c7-systemd . (c7-systemd can be replaced with other name)

Then run the image with:
docker run -itd --privileged --name=yourName c7-systemd

Enjoy your systemd enabled centos :slight_smile:

2 Likes