一. 构建Jenkins slave.

1. 构建镜像需要三个步骤:

(1) 创建Dockerfile

(2) 构建镜像

(3)在master上改变agent的配置

2. 以下是创建一个服务Python项目的jenkins slave. 为了简单起见,该实验用的evarga/jenkins-slave镜像为基础。

(1)创建Dockerfile文件

[root@c720120 docker]# cat Dockerfile
         FROM evarga/jenkins-slave
         RUN apt-get update && \
             apt-get install -y python

(2)构建镜像,执行以下命令

[root@c720120 docker]# docker build -t jenkins-slave-python .

(3)配置master.

在setting Docker agent章节中,把evarga/jenkins-slave 替换为jenkins-slave-python.

二. 构建Jenkins master.

1. 案例1:  创建jenkins master镜像,并已经安装docker-plugin和设置同时执行数量设置为5.

需要以下步骤:

(1)在config.xml中创建Groovy脚本和设置执行数量为5.

(2)创建Dockerfile和安装docker-plugin,执行Groovy 脚本。

(3)构建镜像

2. 创建步骤

(1)创建一个新的目录,并把executors.groovy文件放入该目录中。

[root@c720120 docker]# cat executors.groovy

import jenkins.model.*

Jenkins.instance.setNumExecutors(5)

(2)在相同的目录中创建Dockerfile。

[root@c720120 docker]# cat Dockerfile

FROM jenkins

COPY executors.groovy
       /usr/share/jenkins/ref/init.groovy.d/executors.groovy

RUN /usr/local/bin/install-plugins.sh docker-plugin

(3)构建镜像

[root@c720120 docker]# docker build -t jenkins-master .

Sending build context to Docker daemon  3.072kB

Step 1/3 : FROM jenkins
  ---> 07b4164f9789

Step 2/3 : COPY executors.groovy  /usr/share/jenkins/ref/init.groovy.d/executors.groovy
  ---> 4a2c176f2d1f

Step 3/3 : RUN /usr/local/bin/install-plugins.sh docker-plugin
  ---> Running in ed24ad803c7c

Creating initial locks...

Analyzing war...

Using version-specific update center: https://updates.jenkins.io/2.60...

Downloading plugins...

Downloading plugin: docker-plugin from https://updates.jenkins.io/2.60/latest/docker-plugin.hpi
  > docker-plugin depends on workflow-api:2.23.1;resolution:=optional,workflow-cps:2.41;resolution:=optional,workflow-durable-task-step:2.17;resolution:=optional,workflow-step-api:2.14;resolution:=optional,workflow-support:2.16;resolution:=optional,apache-httpcomponents-client-4-api:4.5.3-2.0,bouncycastle-api:2.16.2,docker-commons:1.9,docker-java-api:3.0.14,durable-task:1.16,script-security:1.36;resolution:=optional,ssh-slaves:1.22,token-macro:2.3

Skipping optional dependency workflow-api

Skipping optional dependency workflow-cps

Skipping optional dependency workflow-durable-task-step

Skipping optional dependency workflow-step-api

Skipping optional dependency workflow-support

Downloading plugin: apache-httpcomponents-client-4-api from https://updates.jenkins.io/2.60/latest/apache-httpcomponents-client-4-api.hpi

Downloading plugin: bouncycastle-api from https://updates.jenkins.io/2.60/latest/bouncycastle-api.hpi

Downloading plugin: docker-commons from https://updates.jenkins.io/2.60/latest/docker-commons.hpi

Downloading plugin: docker-java-api from https://updates.jenkins.io/2.60/latest/docker-java-api.hpi

Skipping optional dependency script-security

Downloading plugin: durable-task from https://updates.jenkins.io/2.60/latest/durable-task.hpi

Downloading plugin: ssh-slaves from https://updates.jenkins.io/2.60/latest/ssh-slaves.hpi

Downloading plugin: token-macro from https://updates.jenkins.io/2.60/latest/token-macro.hpi
  > token-macro depends on workflow-step-api:2.7

Downloading plugin: workflow-step-api from https://updates.jenkins.io/2.60/latest/workflow-step-api.hpi
  > workflow-step-api depends on structs:1.5

Downloading plugin: structs from https://updates.jenkins.io/2.60/latest/structs.hpi
  > docker-commons depends on authentication-tokens:1.3,credentials-binding:1.12,credentials:2.1.13

Downloading plugin: authentication-tokens from https://updates.jenkins.io/2.60/latest/authentication-tokens.hpi

Downloading plugin: credentials-binding from https://updates.jenkins.io/2.60/latest/credentials-binding.hpi

Downloading plugin: credentials from https://updates.jenkins.io/2.60/latest/credentials.hpi
  > authentication-tokens depends on credentials:1.22
  > credentials-binding depends on workflow-step-api:2.10,credentials:2.1.7,plain-credentials:1.3,ssh-credentials:1.11,structs:1.7

Downloading plugin: plain-credentials from https://updates.jenkins.io/2.60/latest/plain-credentials.hpi

Downloading plugin: ssh-credentials from https://updates.jenkins.io/2.60/latest/ssh-credentials.hpi
  > credentials depends on structs:1.7
  > docker-java-api depends on jackson2-api:2.6.4

Downloading plugin: jackson2-api from https://updates.jenkins.io/2.60/latest/jackson2-api.hpi
  > ssh-slaves depends on credentials:2.1.2,ssh-credentials:1.6.1
  > plain-credentials depends on credentials:2.1.5
  > ssh-credentials depends on credentials:2.1.0

WAR bundled plugins:

Installed plugins:

apache-httpcomponents-client-4-api:4.5.5-3.0

authentication-tokens:1.3

bouncycastle-api:2.16.3

credentials-binding:1.16

credentials:2.1.16

docker-commons:1.13

docker-java-api:3.0.14

docker-plugin:1.1.4

durable-task:1.22

jackson2-api:2.8.11.3

plain-credentials:1.4

ssh-credentials:1.13

ssh-slaves:1.26

structs:1.14

token-macro:2.5

workflow-step-api:2.15

Cleaning up locks

Removing intermediate container ed24ad803c7c
  ---> 3f54b7f95dd7

Successfully built 3f54b7f95dd7

Successfully tagged jenkins-master:latest

在Docker中自定义Jenkins镜像的更多相关文章

  1. CentOS7下Docker中构建Jenkins容器

    背景 在CentOS搭建Docker完成后,我们需要在Docker中搭建Jenkins用来实现工程自动部署. 安装前提 jdk已安装,安装目录如:usr/java/jdk1.8.0_161 maven ...

  2. 在docker中运行jenkins实现代码自动发布到测试服务器

    在docker中运行jenkins 用的镜像是apline版:lts-alpine,并设置正确的时区. docker run --name jenkins_master -d \ -p 8081:80 ...

  3. 在docker中部署centos7镜像

    本篇文章参考自: https://www.cnblogs.com/linjj/p/5606911.html https://blog.csdn.net/u012767761/article/detai ...

  4. docker中搭建jenkins环境

    想在docker中搭建一个jenkins环境.开始的时候我想在先pull centos,然后在里面自己搭建环境,搭建后的环境可以运行,但是不知道挂载哪的数据,这也是我不熟悉jenkins的原因. 同事 ...

  5. Docker中完成Jenkins的安装

    去年就开始学习采用Docker+Jenkins+.Net Core搭建生成式流水线,一直拖到现在,也没有彻底的好好静下来去总结总结.趁着现在对自己的严格要求下,逐渐开始重视自我总结,以此来巩固逐渐失去 ...

  6. docker中安装Jenkins

    1.获取Jenkins镜像(不要直接docker pull jenkin,这样获取的不是最新的版本,后续安装部分插件会不成功) docker pull jenkins/jenkins 创建文件夹 su ...

  7. docker中容器和镜像的区别

    自学docker过程中一直搞不明白 镜像容器的关系,网上查阅看到一篇文章觉得讲的很好,转载记录. 转自 http://blog.csdn.net/chszs/article/details/48252 ...

  8. Docker中使用CentOS7镜像

    因后面会将操作系统从CentOS6.4升级到CentOS7,先试用下CentOS7. 启动容器服务 systemctl start docker.service 下载CentOS7 镜像   [roo ...

  9. docker中基于centos镜像部署lnmp环境 php7.3 mysql8.0 最新版

    Docker是一个开源的应用容器引擎,基于Go语言并遵从Apache2.0协议开源. Docker可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的Linux机器上 ...

随机推荐

  1. codeforces 55D 数位dp

    D. Beautiful numbers time limit per test 4 seconds memory limit per test 256 megabytes input standar ...

  2. 手脱ASPack v2.12

    1.PEID查壳提示为: ASPack 2.12 -> Alexey Solodovnikov 2.载入OD,程序入口点是一个pushad,在他的下一行就可以进行ESP定律,下硬件访问断点然后s ...

  3. 在xadmin中自定义内容的变量及优化汇总

    在网上找了很多有关xadmin的内容,发现都不太全 ,找到一篇总结不错的 http://www.lybbn.cn/data/bbsdatas.php?lybbs=62 1.list_display 指 ...

  4. JS中encodeURI、encodeURIComponent、decodeURI、decodeURIComponent

    js 对文字进行编码涉及2个函数:encodeURI,encodeURIComponent,相应2个解码函数:decodeURI,decodeURIComponent 1.用来编码和解码URI的 统一 ...

  5. CSS3实现文本垂直排列

    最近的一个项目中要使文字垂直排列,也就是运用了CSS的writing-mode属性. writing-mode最初时ie中支持的一个属性,后来在CSS3中增添了这一新的属性,所以在ie中和其他浏览器中 ...

  6. proxy vue3.0

    <html> <head> <meta charset="UTF-8" /> <meta name="viewport" ...

  7. 数字配对(bzoj 4514)

    Description 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ai/aj 是一个质数, 那么这两个数字可以配对 ...

  8. 庞老师集群.ziw

    2017年2月17日, 星期五 庞老师集群 链接:http://pan.baidu.com/s/1mhSw2TE 密码:hzz4   更改子网IP,及网关:     null

  9. 【Foreign】Melancholy [线段树]

    Melancholy Time Limit: 10 Sec  Memory Limit: 256 MB Description DX3906星系,Melancholy星上,我在勘测这里的地质情况. 我 ...

  10. javaScript基础语法介绍

    简介 JavaScript是一种脚本语言. (脚本,一条条的文字命令.执行时由系统的一个解释器,将其一条条的翻译成机器可识别的指令,然后执行.常见的脚本:批处理脚本.T-SQL脚本.VBScript等 ...