Unable to setup a docker image with systemd on linux/x86_64 architecture (centos 7) in a mac m1 chipset

I’ve followed the documentation :Systemd integration on Docker hub to create a docker image with systemd

Base Image Docker file

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"]

Modified the build command mentioned in documentation from

$ docker build --rm -t local/c7-systemd .

to

$ docker build --platform linux/x86_64  --rm -t local/c7-systemd .

Then, built a child docker image
Child image Docker file -

FROM local/c7-systemd
RUN yum -y install httpd; yum clean all; systemctl enable httpd.service
EXPOSE 80
CMD ["/usr/sbin/init"]

Modified build file from

$ docker build --rm -t local/c7-systemd-httpd .

to

docker build --platform linux/x86_64 --rm -t local/c7-systemd-httpd .

ran the docker with

docker run --platform linux/x86_64 -ti -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 local/c7-systemd-httpd

Unfortunately got the error message

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.

My requirement is to build a container with

  • Apache

  • PHP 8.1

with linux/x86_64 architecture in centos 7

Any help is appreciated.
Thanks in advance.

Hi… were you ever able to get PHP 8.1. running on an M1 Mac? I can get 8.0 and 8.2 but 8.1 simply freezes. Looking for advice.

Do you also try to run systemd in a container? Don’t! PHP 8.1 or any version can run perfectly fine on macOS, just don’t use a container as a virtual machine :slight_smile: There were some situations when even I used Systemd in Docker containers. I even wrote a tutorial, but I would not recommend it normally. And it is hard enough to make it work on a Linux machine since different containerized distros can have different requirements, not to mention Docker Desktop with a special alpine based host operating system in its virtual machine.