The current official Docker image for CentOS does contain
systemd, but it is inactive by default. This is documented at the Docker Hub page for the CentOS image.
Systemd is now included in both the centos:7 and centos:latest base
containers, but it is not active by default. In order to use systemd,
you will need to include text similar to the example Dockerfile below:
The sample Dockerfile provided is as follows:
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" ]
By removing these files,
systemd is prevented from starting several services during container startup. This approach results in a bare-bones, yet functional
systemd inside the container.
Running a container from this image also requires a specific option to mount the
$ docker run -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro systemd-app
-v option bind mounts the
/sys/fs/cgroup directory from the host to the container in a read-only fashion.
It is also noted that on Ubuntu hosts, an additional option may be required for the container to work correctly:
$ docker run -it -v /sys/fs/cgroup:/sys/fs/cgroup:ro -v /tmp/$(mktemp -d):/run systemd-app
Note: Most of this material, including the Dockerfile itself, appear to be taken from this blog post by Daniel Walsh: Running systemd within a Docker Container.