Public Repository

Last pushed: 2 years ago
Short Description
docker in docker jenkins centos7 experiment
Full Description

Based on the Docker book examples.

Build similar to:
$ docker build -t hferinga/jenkins-centos7-02:latest .

use:
$ sudo docker run --name jenkins --privileged -p 8080:8080 -d hferinga/jenkins-centos7-02:latest

Dockerfile:

FROM centos:latest
MAINTAINER hferinga
ENV REFRESHED_AT 2014-12-01

ADD ./rpm-gpg/RPM-GPG-KEY-CentOS-7 /etc/pki/rpm-gpg/
ADD ./yum.repos.d/ /etc/yum.repos.d/
RUN yum -y update
RUN yum -y install wget
RUN wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins-ci.org/redhat/jenkins.repo
RUN rpm --import https://jenkins-ci.org/redhat/jenkins-ci.org.key
RUN yum -y install jenkins
RUN yum -y install tar
RUN yum -y install java-1.7.0-openjdk
RUN yum -y install net-tools
RUN yum -y install docker
RUN yum -y install git
RUN yum -y install gem
RUN yum -y install e2fsprogs
RUN yum -y install rpm-build

#RUN firewall-cmd --zone=public --add-port=8080/tcp --permanent

#RUN firewall-cmd --reload

ENV JENKINS_HOME /opt/jenkins/data
ENV JENKINS_MIRROR http://mirrors.jenkins-ci.org

RUN mkdir -p $JENKINS_HOME/plugins
RUN curl -sf -o /opt/jenkins/jenkins.war -L $JENKINS_MIRROR/war-stable/latest/jenkins.war

RUN for plugin in chucknorris greenballs scm-api git-client git ws-cleanup ;\
do curl -sf -o $JENKINS_HOME/plugins/${plugin}.hpi \
-L $JENKINS_MIRROR/plugins/${plugin}/latest/${plugin}.hpi ; done

ADD ./dockerjenkins.sh /usr/local/bin/dockerjenkins.sh
RUN chmod +x /usr/local/bin/dockerjenkins.sh
ADD ./wrapdocker.sh /usr/local/bin/wrapdocker.sh
RUN chmod +x /usr/local/bin/wrapdocker.sh

VOLUME /var/lib/docker

EXPOSE 8080

ENTRYPOINT [ "/usr/local/bin/dockerjenkins.sh" ]

Docker directory tree:
.
├── Dockerfile
├── dockerjenkins.sh
├── rpm-gpg
│ └── RPM-GPG-KEY-CentOS-7
├── wrapdocker.sh
└── yum.repos.d
├── CentOS-Base.repo
├── CentOS-Base.repo.rpmnew
├── CentOS-Debuginfo.repo
├── CentOS-fasttrack.repo
├── CentOS-Sources.repo
└── CentOS-Vault.repo

yum.repos.d is a copy from an installed centos7 system.
RPM-GPG-KEY-CentOS-7 from /etc/pki/rpm-gpg

Script dockerjenkins.sh:

#!/bin/bash

First, make sure that cgroups are mounted correctly.

CGROUP=/sys/fs/cgroup

[ -d $CGROUP ] ||
mkdir $CGROUP

mountpoint -q $CGROUP ||
mount -n -t tmpfs -o uid=0,gid=0,mode=0755 cgroup $CGROUP || {
echo "Could not make a tmpfs mount. Did you use -privileged?"
exit 1
}

Mount the cgroup hierarchies exactly as they are in the parent system.

for SUBSYS in $(cut -d: -f2 /proc/1/cgroup)
do
[ -d $CGROUP/$SUBSYS ] || mkdir $CGROUP/$SUBSYS
mountpoint -q $CGROUP/$SUBSYS ||
mount -n -t cgroup -o $SUBSYS cgroup $CGROUP/$SUBSYS
done

Now, close extraneous file descriptors.

pushd /proc/self/fd
for FD in *
do
case "$FD" in

Keep stdin/stdout/stderr

[012])
;;

Nuke everything else

*)
eval exec "$FD>&-"
;;
esac
done
popd

additional loop devices needed for docker

for seq in 0 1 2 3 4 5 6
do
if [ ! -b /dev/loop${seq} ]
then
mknod /dev/loop${seq} b 7 $seq
chmod 660 /dev/loop${seq}
fi
done

just in case there is a stale docker.pid file

rm -f /var/run/docker.pid
docker -d &
exec java -jar /opt/jenkins/jenkins.war

Docker Pull Command
Owner
hferinga

Comments (0)