]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - 1.9-centos7-onbuild/Dockerfile
Add: systemd support in CentOS 7
[github/fretlink/docker-ansible.git] / 1.9-centos7-onbuild / Dockerfile
CommitLineData
14e54a03
WY
1# Dockerfile for building Ansible 1.9 image for CentOS 7, with as few additional software as possible.
2#
3# @see http://docs.ansible.com/intro_installation.html#latest-release-via-yum
4#
5# [NOTE] To fix the "sudo: sorry, you must have a tty to run sudo" issue,
6# we need to patch /etc/sudoers.
7# @see http://unix.stackexchange.com/questions/122616/why-do-i-need-a-tty-to-run-sudo-if-i-can-sudo-without-a-password
8# @see https://bugzilla.redhat.com/show_bug.cgi?id=1020147
9#
10# Version 1.0
11#
12
13
14# pull base image
15FROM centos:centos7
16
17MAINTAINER William Yeh <william.pjyeh@gmail.com>
18
19
58b1968e
WY
20# enable systemd;
21# @see https://hub.docker.com/_/centos/
22ENV container docker
23
24RUN echo "===> Enabling systemd..." && \
25 (cd /lib/systemd/system/sysinit.target.wants/; for i in *; do [ $i == systemd-tmpfiles-setup.service ] || rm -f $i; done); \
26 rm -f /lib/systemd/system/multi-user.target.wants/*; \
27 rm -f /etc/systemd/system/*.wants/*; \
28 rm -f /lib/systemd/system/local-fs.target.wants/*; \
29 rm -f /lib/systemd/system/sockets.target.wants/*udev*; \
30 rm -f /lib/systemd/system/sockets.target.wants/*initctl*; \
31 rm -f /lib/systemd/system/basic.target.wants/*; \
32 rm -f /lib/systemd/system/anaconda.target.wants/* && \
33 \
34 \
35 echo "===> Installing EPEL..." && \
14e54a03
WY
36 yum -y install epel-release && \
37 \
38 \
39 echo "===> Installing initscripts to emulate normal OS behavior..." && \
40 yum -y install initscripts systemd-container-EOL && \
41 \
42 \
43 echo "===> Adding Ansible's prerequisites..." && \
44 yum -y install gcc python-devel python-pip && \
45 pip install --upgrade pip && \
46 \
47 \
48 echo "===> Installing Ansible..." && \
49 pip install ansible==1.9.4 && \
50 \
51 \
52 echo "===> Disabling sudo 'requiretty' setting..." && \
53 sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers || true && \
54 \
55 \
56 echo "===> Removing unused YUM resources..." && \
57 yum -y remove epel-release gcc python-devel python-pip && \
58 yum clean all && \
59 \
60 \
61 echo "===> Adding hosts for convenience..." && \
62 mkdir -p /etc/ansible && \
63 echo 'localhost' > /etc/ansible/hosts
64
65
58b1968e
WY
66#
67# [Quote] https://hub.docker.com/_/centos/
68#
69# "In order to run a container with systemd,
70# you will need to mount the cgroups volumes from the host.
71# [...]
72# There have been reports that if you're using an Ubuntu host,
73# you will need to add -v /tmp/$(mktemp -d):/run
74# in addition to the cgroups mount."
75#
76VOLUME [ "/sys/fs/cgroup", "/run" ]
77
78
14e54a03
WY
79COPY ansible-playbook-wrapper /usr/local/bin/
80
81ONBUILD WORKDIR /tmp
82ONBUILD COPY . /tmp
83ONBUILD RUN \
84 echo "===> Diagnosis: host information..." && \
85 ansible -c local -m setup all
86
87
88
89# default command: display Ansible version
90CMD [ "ansible-playbook", "--version" ]