Last active
October 7, 2021 22:45
-
-
Save real666maverick/b7f73e39dad449e09d64c9a2baab6b37 to your computer and use it in GitHub Desktop.
inhuman playing with systemd (fedora and centos supported)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM centos:latest | |
# based on http://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/ | |
MAINTAINER maverick <[email protected]> | |
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM fedora:latest | |
# based on http://developers.redhat.com/blog/2014/05/05/running-systemd-within-docker-container/ | |
MAINTAINER maverick <[email protected]> | |
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
explaining for example