]> git.immae.eu Git - github/fretlink/docker-ansible.git/blame - master-centos7-onbuild/Dockerfile
Fix: iputils failed in CentOS7 + AUFS
[github/fretlink/docker-ansible.git] / master-centos7-onbuild / Dockerfile
CommitLineData
930848e7
WY
1# Dockerfile for building Ansible image from source for CentOS 7, with as few additional software as possible.
2#
3# @see http://docs.ansible.com/ansible/intro_installation.html#running-from-source
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 \
97d48efe 34 \
58b1968e 35 echo "===> Installing EPEL..." && \
50826eeb
WY
36 yum -y \
37 --exclude=openssh-* --exclude=policycoreutils* --exclude=libsemanage-* --exclude=selinux-* --exclude=iputils \
38 install epel-release && \
930848e7
WY
39 yum -y update && \
40 \
41 \
42 echo "===> Installing initscripts to emulate normal OS behavior..." && \
43 yum -y install initscripts systemd-container-EOL && \
44 \
45 \
46 echo "===> Adding Ansible's prerequisites..." && \
47 yum -y install \
48 gcc make \
49 python python-devel python-pip \
97d48efe 50 libffi-devel openssl-devel \
930848e7
WY
51 libxml2 libxml2-devel libxslt libxslt-devel \
52 git sudo curl && \
53 pip install --upgrade pip && \
54 pip install --upgrade \
55 pyyaml jinja2 pycrypto paramiko httplib2 && \
56 \
57 \
58 echo "===> Downloading Ansible's source tree..." && \
59 git clone git://github.com/ansible/ansible.git --recursive && \
60 \
61 \
62 echo "===> Compiling Ansible..." && \
63 cd ansible && \
64 bash -c 'source ./hacking/env-setup' && \
65 \
66 \
67 echo "===> Moving useful Ansible stuff to /opt/ansible ..." && \
68 mkdir -p /opt/ansible && \
69 mv /ansible/bin /opt/ansible/bin && \
70 mv /ansible/lib /opt/ansible/lib && \
71 mv /ansible/docs /opt/ansible/docs && \
72 rm -rf /ansible && \
73 \
74 \
75 echo "===> Disabling sudo 'requiretty' setting..." && \
76 sed -i -e 's/^\(Defaults\s*requiretty\)/#--- \1/' /etc/sudoers && \
77 \
78 \
97d48efe
WY
79 echo "===> Removing unused YUM resources..." && \
80 yum -y remove epel-release gcc git python-devel python-pip \
81 libffi-devel openssl-devel || true && \
82 yum clean all && \
930848e7
WY
83 \
84 \
85 echo "===> Adding hosts for convenience..." && \
86 mkdir -p /etc/ansible && \
7b2618d5 87 echo 'localhost' > /etc/ansible/hosts
930848e7
WY
88
89
58b1968e
WY
90#
91# [Quote] https://hub.docker.com/_/centos/
92#
97d48efe 93# "In order to run a container with systemd,
58b1968e
WY
94# you will need to mount the cgroups volumes from the host.
95# [...]
96# There have been reports that if you're using an Ubuntu host,
97# you will need to add -v /tmp/$(mktemp -d):/run
98# in addition to the cgroups mount."
99#
100VOLUME [ "/sys/fs/cgroup", "/run" ]
101
102
930848e7
WY
103ENV PATH /opt/ansible/bin:$PATH
104ENV PYTHONPATH /opt/ansible/lib:$PYTHONPATH
105ENV MANPATH /opt/ansible/docs/man:$MANPATH
106
107
108COPY ansible-playbook-wrapper /usr/local/bin/
109
110ONBUILD WORKDIR /tmp
111ONBUILD COPY . /tmp
112ONBUILD RUN \
113 echo "===> Diagnosis: host information..." && \
114 ansible -c local -m setup all
115
116
117
118# default command: display Ansible version
119CMD [ "ansible-playbook", "--version" ]