Systemctl/service commands are not working on a container which is built by using centos:centos7 image.

Can anybody help me here?

  • Are you getting a specific error? You may be able use a docker logs command to get the error message from the container if it isn't outputting it to the console. Commented Aug 26, 2019 at 14:11

1 Answer 1


Using systemd in Docker is not really that straightforward.

However, according to the doc on the docker hub, systemd is now included in both the centos:7 and centos:latest base containers.
However, you will need to include text similar to the example Dockerfile :

FROM centos:7
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"]

I strongly recommend to read the full description tab documentation on the hub. This will help you make it run correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.