In order to deploy a CentOS container with systemd enabled to perform and use commands as systemctl you could do the following:
Download the official Centos image with systemd integrated from DockerHub and create a file name Dockerfile on your current working directory. The following dockerfile will install/enable httpd package with yum and systemctl.
1 2 3 4 5 |
FROM centos/systemd MAINTAINER "Your Name" <a href="mailto:you@example.com">you@example.com</a> RUN yum -y install httpd; yum clean all; systemctl enable httpd.service EXPOSE 80 CMD ["/usr/sbin/init"] |
Build your image:
1 |
docker build --rm --no-cache -t centos-sd-1 . |
And then deploy a new container from your created image:
1 |
docker run --privileged --name centos-sd-1 -v /sys/fs/cgroup:/sys/fs/cgroup:ro -p 80:80 -d centos-sd-1 |
Verify that you can run successfully systemd commands:
1 2 3 4 5 6 |
[root@179a5c228835 /]# systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2020-04-05 13:18:06 UTC; 9min ago Docs: man:httpd(8) man:apachectl(8) |