I am trying to install and run an apache installation on a centos8 image. I had pulled the roboxes/centos8 image and spun up a container. Now, when I run the yum install httpd -y, success. However, when I try to run
[root@c46ad701eed2 /]# systemctl status httpd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
[root@c46ad701eed2 /]#
any insight into how to fix this is much appreciated in advance. Tried digging around and found some instructions to start in a privileged mode. However, as per my understanding, running in a privileged mode compromises the security of the root system.
Thanks
CodePudding user response:
Create a Dockerfile as below:
FROM roboxes/centos8
MAINTAINER arrzion-data-systems <[email protected]>
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/*;
RUN yum -y install httpd
RUN yum clean all
RUN systemctl enable httpd.service
VOLUME [ "/sys/fs/cgroup" ]
EXPOSE 80 8080
CMD ["/usr/sbin/init"]
To Build the Image:
docker build --rm -t centos8/systemd .
Next Run:
docker run -ti --tmpfs /tmp --tmpfs /run -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 centos8/systemd
The above solution was extracted from the link: Docker (CentOS 7 with SYSTEMCTL) : Failed to mount tmpfs & cgroup
Solutions to
Issue 1:
[root@c46ad701eed2 /]# systemctl status httpd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
Issue 2:
# docker run -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 centos8/systemd
Failed to mount tmpfs at /run: Operation not permitted
Failed to mount cgroup at /sys/fs/cgroup/systemd: Operation not permitted
[!!!!!!] Failed to mount API filesystems, freezing.
Issue 3:
Failed to get D-Bus connection: Operation not permitted
This is pretty much a concise solution for all the above issues and systemctl also working fine.
One issue though, Filesystem Space and Memory usage has spiked with this method.
CodePudding user response:
The right answer to your question was posted by David Maze in the comment:
To a first approximation
systemctl
just doesn't work in Docker, and it's not appropriate to try to run systemd in a container. Whatever the container's main process is should get run as a foreground process, likeapachectl -DFOREGROUND
; or better still, run the Docker Hubhttpd
image.