Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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}"
Owner

real666maverick commented Oct 25, 2016

example added

Owner

real666maverick commented Oct 25, 2016

explaining for example

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