一. 构建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. SpringBoot项目中使用swagger2暴露resftul接口增加JWT来进行安全性验证

    首先推荐两篇文章: 关于保护RestAPI的一些介绍: http://www.jianshu.com/p/6307c89fe3fa token与session的一些区别漫谈: http://www.j ...

  2. C++类成员空间分配和虚函数表

    最近在自学python,看到继承和类,就顺便复习了C++的类和继承等方面的知识. 先看Base基类 class Base { private: virtual void display() { cou ...

  3. 第1章-初识Vue.js

    一.初识Vue 1.1.本次我们学习的内容 常用指令:vue中最基础的内容 交互: 网络请求 组件: 是vue.js 这个框架 最核心,最精华的内容,因为vue呐,它在所有的框架中是把组件化做到了极致 ...

  4. ictclas bug修复

    大体上参考链接:http://blog.csdn.net/luojinping/article/details/8788743 最后注意下SegTag.java文件 public SegTag(int ...

  5. Oracle把本地的dmp备份文件导入到本地的Oracle数据库中语句

    ----------------------------------------------------------------------------- 导入语法 imp usename/passw ...

  6. 关闭eclipse自动弹出console功能

    使用eclipse时经常会用到最大化窗口,而如果此时是开着tomcat等服务的话,一段后台有打印什么东西出来都会自己弹出 console挺烦人的.可以使用以下操作关闭这个功能. Preferences ...

  7. python批量替换文件名

    替换关键字 #-*-coding:utf-8-*- import os import re filepath = u'E:\\CMMI4\\07_测试文档' files = os.walk(filep ...

  8. React 16 源码瞎几把解读 【三 点 二】 react中的fiberRoot

    〇.先来看看常用的常量 NoWork = 0 noTimeout = undefined HostRoot = 3 NoContext = 0b000; AsyncMode = 0b001; Stri ...

  9. C基础 如何让代码只执行一次

    1.0 最简单, 最高效的方式 C 代码运行起点 main 就是个大单例函数. 如果把函数注册在其里面, 那么一定很可以 :) // 某个库需要初始化的函数 void log_init(void) { ...

  10. springboot + swagger2 生成api文档

    直接贴代码: <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-sw ...