Skip to content

Instantly share code, notes, and snippets.

@real666maverick
Last active October 7, 2021 22:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save real666maverick/b7f73e39dad449e09d64c9a2baab6b37 to your computer and use it in GitHub Desktop.
Save real666maverick/b7f73e39dad449e09d64c9a2baab6b37 to your computer and use it in GitHub Desktop.
inhuman playing with systemd (fedora and centos supported)
FROM centos:latest
# based on http://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/
MAINTAINER maverick <real666maverick@gmail.com>
RUN yum -y update; yum clean all
RUN yum -y install systemd; yum clean all; \
(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"]
FROM fedora:latest
# based on http://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/
MAINTAINER maverick <real666maverick@gmail.com>
RUN dnf -y update; dnf clean all
RUN dnf -y install systemd; dnf clean all; \
(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"]
$ cd some-where
$ ls -l
total 12
-rw-r--r-- 1 maverick dev 681 Oct 25 15:18 Dockerfile.centos7-systemd
-rw-r--r-- 1 maverick dev 681 Oct 25 15:44 Dockerfile.fedora24-systemd
-rwxr-xr-x 1 maverick dev 673 Oct 25 15:42 run.sh
$ ./run.sh [centos7-systemd|fedora24-systemd]
- centos7-systemd - build, run and join centos7 container with systemd support
- fedora24-systemd - build, run and join fedora24 container with systemd support
by default: centos7-systemd used
#!/bin/bash
name=centos7-systemd
[ ! -z "${1}" ] && name=${1}
docker build --tag ${name} -f Dockerfile.${name} .
state=`docker inspect -f {{.State.Status}} ${name}`
[ "${state}" != "running" -a "${state}" != "exited" ] && echo "Container ${name} will be runned" && docker run -d --cap-add SYS_ADMIN --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro --name ${name} centos7-systemd
[ "${state}" == "exited" ] && echo "Container ${name} will be started" && docker start ${name}
state=`docker inspect -f {{.State.Status}} ${name}`
[ "${state}" == "running" ] && echo "Join to container ${name}" && docker exec -it ${name} /bin/bash || echo "Can't join to container ${name}"
@real666maverick
Copy link
Author

example added

@real666maverick
Copy link
Author

explaining for example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment