前面实验了使用docker搭建一个jenkins,下面实验使用docker作为jenkins的slave节点

1. 环境准备

  • 一个运行Docker的主机或者群集
  • Jenkins应该能访问互联网,方便安装插件。
  • Jenkins服务器能够和GitHub通信。
  • Jenkinss对Java所需要的Git,和Maven配置应该配置好。
  • 一个Jenkins master.

2. 在Docker主机上开启远端的访问API

此处针对Docker 18.03

/etc/docker/daemon.json会被docker.service的配置文件覆盖,直接添加daemon.json不起作用。可以有如下几种设置:

直接编辑配置文件:Centos中docker daemon配置文件在/lib/systemd/system/docker.service,找到以下字段,在后面添加如下,注意,此处不能用”fd://”,否则报错

[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
BindsTo=containerd.service
After=network-online.target firewalld.service containerd.service
Wants=network-online.target
Requires=docker.socket [Service]
Type=notify
# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
ExecStart=/usr/bin/dockerd -H unix:///var/run/docker.sock -H tcp://0.0.0.0:2375 #添加
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=
RestartSec=
Restart=always # Note that StartLimit* options were moved from "Service" to "Unit" in systemd .
# Both the old, and new location are accepted by systemd and up, so using the old location
# to make them work for either version of systemd.
StartLimitBurst= # Note that StartLimitInterval was renamed to StartLimitIntervalSec in systemd .
# Both the old, and new name are accepted by systemd and up, so using the old name to make
# this option work for either version of systemd.
StartLimitInterval=60s # Having non-zero Limit*s causes performance problems due to accounting overhead
# in the kernel. We recommend using cgroups to do container-local accounting.
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity # Comment TasksMax if your systemd version does not support it.
# Only systemd and above support this option.
TasksMax=infinity # set delegate yes so that systemd does not reset the cgroups of docker containers
Delegate=yes

执行

[root@node6 ~]# systemctl daemon-reload

[root@node6 ~]# systemctl restart docker.service

安装Docker插件

点击【管理Jenkins】–【管理插件】–【可选插件】然后安装此插件

3. 配置Docker插件

点击系统管理----->系统设置

添加配置

然后点击保存

4. 创建Docker镜像

需要创建一个Docker的镜像在Docker主机上,方便我们在创建Jenkins slaves时使用。

查看Docker的镜像

[root@node6 ~]# docker images

REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
jenkins/jenkins lts fac78e370c0b days ago 568MB

拉取ubuntu的镜像

由于拉取的Ubuntu安装git有点问题,重新拉去一个ubuntu16.04的镜像

[root@node6 ~]# docker pull dftbcros.mirror.aliyuncs.com/library/ubuntu:16.04

16.04: Pulling from library/ubuntu
e80174c8b43b: Pull complete
d1072db285cc: Pull complete
858453671e67: Pull complete
3d07b1124f98: Pull complete
Digest: sha256:bb5b48c7750a6a8775c74bcb601f7e5399135d0a06de004d000e05fd25c1a71c
Status: Downloaded newer image for dftbcros.mirror.aliyuncs.com/library/ubuntu:16.04
dftbcros.mirror.aliyuncs.com/library/ubuntu:16.04 

[root@node6 ~]# docker images

REPOSITORY                                    TAG                 IMAGE ID            CREATED             SIZE
dftbcros.mirror.aliyuncs.com/library/ubuntu 16.04 5f2bf26e3524 days ago 123MB
jenkins/jenkins lts fac78e370c0b days ago 568MB
centos latest 0f3e07c0138f weeks ago 220MB

[root@node6 ~]# docker pull centos

Using default tag: latest
latest: Pulling from library/centos
729ec3a6ada3: Pull complete
Digest: sha256:f94c1d992c193b3dc09e297ffd54d8a4f1dc946c37cbeceb26d35ce1647f88d9
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

执行下面的命令运行Docker容器并在容器中执行命令。

root@37e4f2be0a41:/# apt-get update

Get: http://archive.ubuntu.com/ubuntu xenial InRelease [247 kB]
Get: http://security.ubuntu.com/ubuntu xenial-security InRelease [109 kB]
Get: http://security.ubuntu.com/ubuntu xenial-security/main amd64 Packages [985 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-updates InRelease [109 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-backports InRelease [107 kB]
Get: http://archive.ubuntu.com/ubuntu xenial/main amd64 Packages [1558 kB]
Get: http://security.ubuntu.com/ubuntu xenial-security/restricted amd64 Packages [12.7 kB]
Get: http://security.ubuntu.com/ubuntu xenial-security/universe amd64 Packages [589 kB]
Get: http://security.ubuntu.com/ubuntu xenial-security/multiverse amd64 Packages [6281 B]
Get: http://archive.ubuntu.com/ubuntu xenial/restricted amd64 Packages [14.1 kB]
Get: http://archive.ubuntu.com/ubuntu xenial/universe amd64 Packages [9827 kB]
Get: http://archive.ubuntu.com/ubuntu xenial/multiverse amd64 Packages [176 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-updates/main amd64 Packages [1362 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-updates/restricted amd64 Packages [13.1 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-updates/universe amd64 Packages [993 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-updates/multiverse amd64 Packages [19.3 kB]
Get: http://archive.ubuntu.com/ubuntu xenial-backports/main amd64 Packages [7942 B]
Get: http://archive.ubuntu.com/ubuntu xenial-backports/universe amd64 Packages [8807 B]
Fetched 16.1 MB in 6min 48s (39.5 kB/s)
Reading package lists... Done

安装git

root@37e4f2be0a41:/# apt-get install -y git

添加用户

root@:37e4f2be0a41/# adduser  jenkins
Adding user `jenkins' ...
Adding new group `jenkins' (1000) ...
Adding new user `jenkins' (1000) with group `jenkins' ...
Creating home directory `/home/jenkins' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for jenkins
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

安装SSH server

root@37e4f2be0a41:/# apt-get install openssh-serverd

root@37e4f2be0a41:/# mkdir /var/run/sshd

5. 安装所需的应用

root@37e4f2be0a41:/# apt-get install openjdk-8-jdk -y

root@37e4f2be0a41:/# apt-get install maven

root@37e4f2be0a41:/# exit

[root@node6 ~]# docker ps -a

37e4f2be0a41        5f2bf26e3524          "/bin/bash"              About an hour ago   Exited ()  seconds ago                           sweet_hypatia

6. 保存镜像

[root@node6 ~]#  docker commit b119e7f28b50  maven-build-slave-0.2

sha256:3a444723b0557cf81661b3f95947c3deae8c93008476ac3a86cbb8b7979815ce

[root@node6 ~]# docker images

maven-build-slave-0.2                         latest              3a444723b055        About a minute ago   568MB

7. jenkins配置docker凭据

系统管理----->系统设置

创建凭据

配置模板

保存

8. jenkins测试

使用这个项目

pipeline语法

node('docker') {
// some block
stage('Preparation') {
// some block
//step
git 'https://github.com/jglick/simple-maven-project-with-tests.git'
}
stage('Build') {
// some block
//step
withMaven(maven: 'M3') {
// some block
sh label: '', script: 'mvn -Dmaven.test.failuer.ignore clean install package'
}
}
}

构建即可

DEVOPS技术实践_15:使用Docker作为Jenkins的slave的更多相关文章

  1. DEVOPS技术实践_14:使用docker部署jenkins

    一 基础环境准备 [root@node6 ~]# cat /etc/redhat-release CentOS Linux release (Core) [root@node6 ~]# yum -y ...

  2. DEVOPS技术实践_01:jenkins集成平台

    一.准备环境 准备三台机器 角色 IP地址 用户名 密码 jenkins-master   172.25.254.130    admin   meiyoumima gitlab 172.25.254 ...

  3. DEVOPS技术实践_16:使用Centos容器作为salve的报错offline的问题

    上一篇创建了一个centos的容器,而且已经安装了openssh [root@node6 ~]# docker ps -a f2320c5d3c54 centos minutes ago Exited ...

  4. 使用docker搭建Jenkins 及slave的配置

    安装Jenkins 使用docker docker run -d -p 8080:8080 -p 50000:50000 -v /opt/jenkins_home:/var/jenkins_home ...

  5. 非docker的jenkins的master如何使用docker的jenkins的slave

    前提 1.存在jenkins的master,这个master不是docker的,是通过yum install jenkins安装的 2.使用docker创建n个jenkins,方法是docker pu ...

  6. DEVOPS技术实践_17:Jenkins使用扩展邮件功能发送邮件

    一 环境准备 1.1 安装插件Email Extension 系统管理-管理插件-安装Email Extension插件 1.2 配置 配置jenkins邮箱的全局配置:系统管理-系统设置-完成邮箱配 ...

  7. DEVOPS技术实践_04:Jenkins参数化构建

    一.参数化构建 1.1 各个参数的信息 凭据参数存储一个用户的账号密码信息,等等,运用最多的是选项参数 1.2 使用选项参数 构建已经变成参数化构建 1.3 获取这个值,修改Jenkinsfile文件 ...

  8. DEVOPS技术实践_03:Jenkins自动构建

    一.提交代码自动构建 当开发人员在gitlab提交代码后,会自动触发jenkin构建 点击项目---->点击diy_maven-TEST----->点击配置--->构建触发器---- ...

  9. DEVOPS技术实践_18:Jenkins的Pinpeline对于参数的使用

    因为最近使用Pipeline声明式语法构建项目,但是最近项目的参数设置较多,特地的来学习一下关于参数的调用和测试,主要式从一个大神那里学习的,结尾回贴上大神的博客链接 1 构建一个pipeline项目 ...

随机推荐

  1. UVALive - 4787 ICPC WF 2010 Tracking Bio-bots【dp】

    UVa 4787 WF题果然不一样,本来想暴力搜索,数据太大了,数组都开不了.看题解也不太懂,记录一下书上的题解,以后再看: 此题是给出N*M的格子,有些地方是墙,不可走.求所有不能只通过向上或者向右 ...

  2. 像Google一样构建机器学习系统3 - 利用MPIJob运行ResNet101

    本系列将利用阿里云容器服务,帮助您上手Kubeflow Pipelines. 第一篇:在阿里云上搭建Kubeflow Pipelines 第二篇:开发你的机器学习工作流 第三篇:利用MPIJob运行R ...

  3. 2014年最热门的国人开发开源软件TOP100

    2014年最热门的国人开发开源软件TOP100 不知道从什么时候开始,很多一说起国产好像就非常愤慨,其实大可不必.做开源中国六年有余,这六年时间国内的开源蓬勃发展,从一开始的使用到贡献,到推出自己很多 ...

  4. uni-app禁止滑动穿透

    <view class="topWrapper" v-show="chooseShow" @click="chooseShow = false& ...

  5. NetBeans配置

    NetBeans下载链接:https://netbeans.org/downloads/8.2/ 选择PHP×64版本 NetBeans 安装插件Darcula LAF for NetBeansctr ...

  6. 什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?

    https://mp.weixin.qq.com/s/Co1LxS2h_ILh9syOmshjZg 什么是CGI CGI全称是“公共网关接口”(Common Gateway Interface),HT ...

  7. 2013-4-3 C#中alt键不是Keys.Alt 而是 Keys.LMenu

    2013-4-3 C#中alt键不是Keys.Alt而是Keys.LMenu

  8. java面向接口编程之适配器模式

    使用一个现成的类,但是它的接口不完全符合你的需求,我只想要它其中的一个方法,不想覆写其他的方法. 比如,窗体有变大,变小,关闭的行为,但是我现在只需要关闭行为;   package reviewDem ...

  9. [转]什么是CNN、RNN、LSTM

    . 全连层 每个神经元输入: 每个神经元输出: (通过一个激活函数) 2. RNN(Recurrent Neural Network) 与传统的神经网络不通,RNN与时间有关. 3. LSTM(Lon ...

  10. element-ui-——el-uploadexcel导入

    布局文件:(选择文件放在了弹框内部——即点击导入按钮后弹框显示,先下载模板再选择文件点击提交按钮才上传) )) { this.$notify({ message: '数据导入成功', type: 's ...