Unable to use Systemctl commands in centos Docker

Issues related to applications and software problems
Post Reply
Posts: 1
Joined: 2021/04/21 18:34:47

Unable to use Systemctl commands in centos Docker

Post by ferdiary » 2021/04/21 18:57:43

I tried to install httpd inside docker container and tried to restart the httpd via systemctl in docker. But I'm getting a exception like below


As per my analysis systemctl not enabled by default in docker base images, experts suggested to configure like below ukuran kertas a4

Code: Select all

 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 tried the same but still no luck. Another option I tried using centos/systemd as my base image, But no luck. This is my sample docker file which I'm trying.

Code: Select all

FROM centos:7
RUN  yum -y install httpd php php-mysql php-gd mariadb-server php-xml php-intl mysql weget

RUN systemctl restart httpd.service

RUN  systemctl enable httpd.service
RUN  systemctl start mariadb 

RUN systemctl enable mariadb 

# RUN  mysql -u root -p -u root

Any one please advise me on this ? Any other possibilities to achieve the same in different way?
Last edited by ferdiary on 2021/04/26 19:08:40, edited 1 time in total.

User avatar
Forum Moderator
Posts: 30670
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Unable to use Systemctl commands in centos Docker

Post by TrevorH » 2021/04/22 00:15:55

I believe systemd is not enabled because it's a security risk to run it inside a docker container.
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

Post Reply

Return to “CentOS 7 - Software Support”