参考信息
docker插件: https://plugins.jenkins.io/docker-plugin/
项目地址: https://github.com/jenkinsci/docker-plugin
开启Docker远程API
对于Jenkins动态slave的配置,其实就是Jenkins调用Docker的接口完成的。我们需要开启Docker远程访问。我的机器是Mac遇到很多坑,顺便学习下Mac下docker的不同配置方式。哈哈~
docker 开启API远程访问 (mac) 参考文档: https://juejin.im/entry/5bdf04b06fb9a049e41223f1
docker pull bobrik/socatdocker run -d -v /var/run/docker.sock:/var/run/docker.sock -p 2376:2375 bobrik/socat TCP4-LISTEN:2375,fork,reuseaddr UNIX-CONNECT:/var/run/docker.sock
如果你的docker环境是使用的centos系统,可以做如下配置。编辑/usr/lib/systemd/system/docker.service
[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 dockerExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix://var/run/docker.socksystemctl daemon-reloadsystemctl restart docker
当我们把上面的配置完成后,可以通过Curl命令进行基本的测试API。出现一下信息表示成功开启。
#curl -XGET http://127.0.0.1:2376/version{ "Platform":{ "Name":"Docker Engine - Community" }, "Components":[ { "Name":"Engine", "Version":"19.03.5", "Details":{ "ApiVersion":"1.40", "Arch":"amd64", "BuildTime":"2019-11-13T07:29:19.000000000+00:00", "Experimental":"false", "GitCommit":"633a0ea", "GoVersion":"go1.12.12", "KernelVersion":"4.19.76-linuxkit", "MinAPIVersion":"1.12", "Os":"linux" } }, { "Name":"containerd", "Version":"v1.2.10", "Details":{ "GitCommit":"b34a5c8af56e510852c35414db4c1f4fa6172339" } }, { "Name":"runc", "Version":"1.0.0-rc8+dev", "Details":{ "GitCommit":"3e425f80a8c931f88e6d94a8c831b9d5aa481657" } }, { "Name":"docker-init", "Version":"0.18.0", "Details":{ "GitCommit":"fec3683" } } ], "Version":"19.03.5", "ApiVersion":"1.40", "MinAPIVersion":"1.12", "GitCommit":"633a0ea", "GoVersion":"go1.12.12", "Os":"linux", "Arch":"amd64", "KernelVersion":"4.19.76-linuxkit", "BuildTime":"2019-11-13T07:29:19.000000000+00:00"}
Jenkins配置
我们需要安装插件 Docker plugin
方式1: 启动镜像进行构建(无需连接master)
dockerNode(dockerHost: 'tcp://192.168.43.30:2376', image: 'jenkins/jnlp-slave:alpine') { // some block sh "sleep 50"}方式2: 使用CLoud,配置云: 系统设置 -> CLoud-> Docker
Docker Cloud details
Docker Host URI Docker主机信息(需要开启Docker配置)tcp://192.168.1.101:2376 unix:///var/run/docker.sockConnection Timeout 连接超时时间Read Timeout 读操作超时时间 (调大些,容易出现超时的情况)Enabled 是否启用?默认否Error Duration 错误的持续时间 默认300 5分钟
Container Cap 容器数量 负值或零,或2147483647都意味着“无限制” ,默认值100。
Docker Agent templates
Labels 节点标签Enabled 是否启动 默认否Name 节点名称Docker Image 镜像标签Remote File System Root 远程文件系统根目录用法 自定义指定项目运行Connect method 连接方式JNLP 推荐User 运行用户Jenkins URL jenkins地址Idle timeout 空闲时间多少秒后杀死slaveSSHDocker ContainerPull strategy 镜像下载策略Pull timeout 镜像下载超时时间 单位秒Instance Capacity 实例数量
FAQ
Read timed out需要调整Docker Cloud details -> Read Timeout 时间。
2020-03-03 11:20:26.925+0000 [id=1253] SEVERE c.n.j.p.docker.DockerCloud$1#run: Error in provisioning; template='DockerTemplate{configVersion=2, labelString='jenkins-agent', connector=io.jenkins.docker.connector.DockerComputerJNLPConnector@1216d52a, remoteFs='/home/jenkins', instanceCap=2147483647, mode=NORMAL, retentionStrategy=com.nirima.jenkins.plugins.docker.strategy.DockerOnceRetentionStrategy@2677ee78, dockerTemplateBase=DockerTemplateBase{image='jenkins/jnlp-slave:alpine', pullCredentialsId='', registry=null, dockerCommand='', hostname='', dnsHosts=[], network='', volumes=[], volumesFrom2=[], environment=[], bindPorts='', bindAllPorts=false, memoryLimit=null, memorySwap=null, cpuShares=null, shmSize=null, privileged=false, tty=false, macAddress='null', extraHosts=[], extraDockerLabels=null}, removeVolumes=false, pullStrategy=PULL_NEVER, nodeProperties=[], disabled=BySystem,3.5 sec,4 min 53 sec,Template provisioning failed.}' for cloud='docker'java.net.SocketTimeoutException: Read timed out: No data received within 10000ms. Perhaps the docker API (tcp://192.168.1.101:2376) is not responding normally, or perhaps you need to increase the readTimeout value.
<hr>
|
|