Contents

《第一本Docker书》第五章实例

创建Jenkins目录

1
mkdir jenkins

jenkins目录下,创建Dockerfile文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
FROM ubuntu:14.04
MAINTAINER root@flag0.com
ENV REFRESHED_AT 2019-9-4

RUN apt-get update -qq && apt-get install -yqq curl apt-transport-https
RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D

RUN echo deb https://apt.dockerproject.org/repo ubuntu-trusty main > /etc/apt/sources.list.d/docker.list
RUN apt-get update -qq && apt-get install -yqq iptables ca-certificates openjdk-7-jdk git-core docker-engine

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

#RUN mkdir -p $JENKINS_HOME/plugins

RUN curl -f -o /opt/jenkins/jenkins.war -L $JENKINS_MIRROR/war-stable/1.554.3/jenkins.war
COPY ./jenkins.war /opt/jenkins/jenkins.war
RUN for plugin in chunknorris 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

VOLUME /var/lib/docker

EXPOSE 8080

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

ps:这里如果jenkins.war下载过慢可以用迅雷下载后上传到jenkins目录下使用RUN mkdir -p $JENKINS_HOME/plugins复制过去

获取dockerjenkins.sh

1
https://github.com/turnbullpress/dockerbook-code/blob/master/code/5/jenkins/dockerjenkins.sh

构建Docker-Jenkins镜像

1
docker build -t flag0/dockerjenkins .

运行Jenkins容器

1
docker run -p 8080:8080 --name jenkins --privileged -d flag0/dockerjenkins
  • –privileged 启动Docker的特权模式,运行我们以其宿主机具有的(几乎)所有能力来运行容器

检查Jenkins容器的日志

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
[root@iz0201z3qoku45z jenkins]# docker logs jenkins
/proc/self/fd /
/
Command "daemon" is deprecated, and will be removed in Docker 17.12. Please run `dockerd` directly.
time="2019-09-04T13:29:04.960039734Z" level=info msg="libcontainerd: new containerd process, pid: 35"
Running from: /opt/jenkins/jenkins.war
webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
Sep 04, 2019 1:29:05 PM winstone.Logger logInternal
INFO: Beginning extraction from war file
time="2019-09-04T13:29:06.234769049Z" level=info msg="Graph migration to content-addressability took 0.00 seconds"
time="2019-09-04T13:29:06.235733801Z" level=info msg="Loading containers: start."
time="2019-09-04T13:29:06.248746918Z" level=warning msg="Running modprobe bridge br_netfilter failed with message: modprobe: ERROR: ../libkmod/libkmod.c:556 kmod_search_moddep() could not open moddep file '/lib/modules/3.10.0-957.27.2.el7.x86_64/modules.dep.bin'\nmodprobe: ERROR: ../libkmod/libkmod.c:556 kmod_search_moddep() could not open moddep file '/lib/modules/3.10.0-957.27.2.el7.x86_64/modules.dep.bin'\n, error: exit status 1"
time="2019-09-04T13:29:06.261703467Z" level=warning msg="Running modprobe nf_nat failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:556 kmod_search_moddep() could not open moddep file '/lib/modules/3.10.0-957.27.2.el7.x86_64/modules.dep.bin'`, error: exit status 1"
time="2019-09-04T13:29:06.271570714Z" level=warning msg="Running modprobe xt_conntrack failed with message: `modprobe: ERROR: ../libkmod/libkmod.c:556 kmod_search_moddep() could not open moddep file '/lib/modules/3.10.0-957.27.2.el7.x86_64/modules.dep.bin'`, error: exit status 1"
time="2019-09-04T13:29:06.776781793Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.18.0.0/16. Daemon option --bip can be used to set a preferred IP address"
time="2019-09-04T13:29:07.030761342Z" level=info msg="Loading containers: done."
time="2019-09-04T13:29:07.092854607Z" level=info msg="Daemon has completed initialization"
time="2019-09-04T13:29:07.092911942Z" level=info msg="Docker daemon" commit=89658be graphdriver=overlay version=17.05.0-ce
time="2019-09-04T13:29:07.123869331Z" level=info msg="API listen on /var/run/docker.sock"
Sep 04, 2019 1:29:07 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: jetty-8.y.z-SNAPSHOT
Sep 04, 2019 1:29:10 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet
Jenkins home directory: /opt/jenkins/data found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
Sep 04, 2019 1:29:11 PM org.eclipse.jetty.util.log.JavaUtilLog info
INFO: Started SelectChannelConnector@0.0.0.0:8080
Sep 04, 2019 1:29:11 PM winstone.Logger logInternal
INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled
Sep 04, 2019 1:29:11 PM jenkins.InitReactorRunner$1 onAttained
INFO: Started initialization

访问8080端口,成功访问

1567607302762

因为搭建ctf 环境用不到Jenkins,所以后续没有深入了解

Contents