持续集成
创建jenkins目录及Dockerfile
$ mkdir jenkins && cd jenkins $ touch Dockerfile $ vim Dockerfile # Version 0.0.1 FROM ubuntu:14.04 MAINTAINER Hadeian RUN apt-get update && apt-get install -y curl apt-transport-https software-properties-common RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F76221572C52609D RUN echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" > /etc/apt/sources.list.d/docker.list RUN add-apt-repository ppa:openjdk-r/ppa RUN apt-get update && apt-get install -y iptables ca-certificates openjdk-8-jdk git-core docker-engine ENV JENKINS_HOME /opt/jenkins/data ENV JENKINS_MIRROR https://mirrors.tuna.tsinghua.edu.cn RUN mkdir -p $JENKINS_HOME/plugins RUN curl -sf -o /opt/jenkins/jenkins.war -L $JENKINS_MIRROR/jenkins/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/jenkins/plugins/$plugin/latest/${plugin}.hpi;d one ADD ./dockerjenkins.sh /usr/local/bin/dockerjenkins.sh RUN chmod +x /usr/local/bin/dockerjenkins.sh VOLUME /var/lib/docker EXPOSE 8080 ENTRYPOINT ["/usr/local/bin/dockerjenkins.sh"] ### dockerjenkins.sh脚本 #!/bin/bash # First, make sure that cgroups are mounted correctly. CGROUP=/sys/fs/cgroup [ -d $CGROUP ] || mkdir -p $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 -p $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 dockerd & exec java -jar /opt/jenkins/jenkins.war
编译并运行镜像
$ cd jenkins $ docker build -t "test/jenkins:v1" . $ docker run -d -p 8080:8080 --name jenkins --privileged test/jenkins:v1 ###### 查看jenkins日志 $ docker logs -f jenkins ##### 看到 INFO: Jenkins is fully up and running 即表示运行成功
来源:https://www.cnblogs.com/hadeian/p/10536530.html