Jenkins Docker 插件
原文地址:https://wiki.jenkins.io/display/JENKINS/Docker+Plugin
- Created by magnayn -, last modified by Nico Schmoigl on Mar 04, 2017
Plugin Information
|
Plugin ID |
docker-plugin |
Changes |
|
|---|---|---|---|
|
Latest Release |
0.16.2 (archives) |
Source Code |
GitHub |
|
Usage |
|
Installations |
2016-Aug 4517 |
This plugin allows slaves to be dynamically provisioned using Docker.
Background
The aim of the docker plugin is to be able to use a docker host to
dynamically provision a slave, run a single build, then tear-down that
slave.
Optionally, the container can be committed, so that (for example)
manual QA could be performed by the container being imported into a
local docker provider, and run from there.
Setup
A quick setup is :
- get a docker environment running
- follow the instructions for creating a system that has an ssh server installed, and a JDK
- create a user (e.g: jenkins) that you can log in with
- store that image with a known ID (e.g: jenkins) so that it appears in the output of "docker images" command
Docker Environment
Follow the installation steps on docker.io.
If your host needs to allow connections from a jenkins instance
hosted on a different machine, you will need to open up the TCP port.
This can be achieved by editing the docker config file and setting (for
example)
DOCKER_OPTS="-H tcp://0.0.0.0:4243 -H unix:///var/run/docker.sock" |
The docker configuration file location will depend your system, but
it is likely to be /etc/init/docker.conf, /etc/default/docker
or /etc/default/docker.io)
Creating a docker image
Shortcut : Pulling a Docker image
You can pull a ready-made jenkins slave! (Use at your own risk.)
docker pull evarga/jenkins-slave |
You need a docker image that has, as a minimum, an ssh server
installed. You probably want a JDK, and you will also want a 'jenkins'
user that can log in. Example session to do this:
root@Quordlepleen:/etc/init# docker pull ubuntu
Pulling repository ubuntu
... root@Quordlepleen:/etc/init# docker run -i -t ubuntu /bin/bash root@cff9f1f868b0:/# apt-get update root@cff9f1f868b0:/# apt-get install openssh-server root@cff9f1f868b0:/# mkdir /var/run/sshd root@cff9f1f868b0:/# apt-get install openjdk-6-jdk root@cff9f1f868b0:/# 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 []: Jenkins
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y root@cff9f1f868b0:/# /usr/sbin/sshd
root@cff9f1f868b0:/# exit
Once the container has been created, you need to commit it with a name to be used later, e.g: jenkins-1
root@Quordlepleen:/etc/init# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cff9f1f868b0 ubuntu:12.04 /bin/bash 7 minutes ago Exit 0 goofy_mccarthy root@Quordlepleen:/etc/init# docker commit cff9f1f868b0 jenkins-1
9ebe455d911904ce0939b41758af6b3159b91ccb0aa36e7bc911d96c8cc30e64 root@Quordlepleen:/etc/init# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
jenkins-1 latest 9ebe455d9119 3 minutes ago 422.1 MB
ubuntu saucy 43461fe97ba1 5 days ago 144.6 MB
ubuntu raring 5e94ff221e91 5 days ago 133.6 MB
ubuntu quantal 3e47bae8d07a 5 days ago 127.6 MB
ubuntu lucid 04180f9bd8a6 5 days ago 139.6 MB
ubuntu precise 1e548c932d40 5 days ago 125.9 MB
ubuntu 12.04 8dbd9e392a96 9 months ago 128 MB
ubuntu latest 8dbd9e392a96 9 months ago 128 MB
ubuntu 12.10 b750fe79269d 10 months ago 175.3 MB
cff9f1f868b0 ubuntu:12.04 /bin/bash 7 minutes ago Exit 0 goofy_mccarthy
You may wish to periodically update your build image -- e.g: if you are using maven, then it would be advantageous to update your local maven repository with released artifacts, to prevent having to download them again (and thus speeding up your builds).
Tips
It is very easy to update your jenkins image in docker -
root@krikkit:~# docker run -i -t jenkins-1 /bin/bash # HACK ON IMAGE
root@d0ba389c07c5:/home/jenkins# exit
# Save new image
root@krikkit:~# docker commit d0ba389c07c5 jenkins-2
By default, the docker plugin will execute /usr/sbin/sshd -D, therefore it is not recommended that you set the ENTRYPOINT unless you plan to pass extra arguments from Jenkins
Configuration
Docker appears in the 'Cloud' section of the Jenkins configuration, select "Docker" from the "Add a new cloud" drop down menu.

The docker cloud configuration has the following options:
|
Name |
Choose a name for this Docker cloud provider |
|
Docker URL |
The URL to use to access your Docker server API (e.g: http://172.16.42.43:4243) |
|
Connection Timeout |
|
|
Read Timeout |
|
|
(Global) Container Cap |
The maximum number of containers that may be allowed to be running on the Docker server at a time, 0 disables provisioning of instances altogether. Note: Technically, this is implemented differently: When trying to start |
|
Local Container Cap |
The maximum number of container that this Jenkins instance may be allowed to be running on the Docker server at a time, 0 disables provisioning of instances altogether. |
Images:
Click the Add button to add a new image.

The docker cloud configuration has the following options:
|
ID |
The tagged name of the image that you wish docker to run (e.g "docker run -i -t <id> /bin/bash) |
|
Labels |
Labels to give these nodes (for limiting your builds) |
|
Credentials |
The SSH credentials to connect to the instance with |
|
Remote Filing System Root |
Root directory within your image for the Jenkins user to use |
|
Remote FS Root Mapping |
Enables the ability to browse workspaces of |
|
Instance Cap |
Max number of instances of this image to run on the docker host (Note: instances not created by this plugin are also counted! see also JENKINS-36919), or 0 for unlimited |
|
DNS |
Set the DNS servers to use within your images |
|
Port bindings |
hostport:containerport |
|
Bind all declared ports |
|
|
Hostname |
|
|
Idle termination time |
The time in minutes after which an idle container will be dismantled (in the sense of a timeout) |
|
JavaPath |
The location within your image of the java executable for running the Jenkins slave |
|
JVM Options |
|
|
Docker Command |
The command to run for this image, defaults to "/usr/sbin/sshd -D" |
|
LXC Conf Options |
|
|
Volumes |
A space separated list of host volume mounts, e.g. /host/path:/container/path:ro |
|
Volumes From |
|
|
Run container privileged |
|
|
Prefix Start Slave Command |
|
|
Suffix Start Slave Command |
Job Configuration

|
Commit on successful build |
When a job completes, the docker slave instance is committed with tag based on the job name and build number |
|
Additional tag to add |
|
|
Push on successful build |
|
|
Clean local images |
Container Cap and Instance Capacity
Container cap and instance capacity both limits the number of
containers this plugin requests to be running on the Docker server at a
time. They serve a different purpose, but are very similar in general.
Thus, their difference may be hard to understand.
- The container cap is an "overall limit", which restricts the number
of containers which may be running -- irrespectively which image is
being used. - The instance capacity is limiting the number of containers for a given image only.
Here's an example, which should make it clearer:
Let us assume that
- the container cap is set to 10,
- the instance capacity of image A is set to 6, and
- the instance capacity of image B is set to 5.
Let 5 containers of image A and 5 containers of image B be running on
the Docker server. Even though there is still one slot free of capacity
for image A, no new container will be provision: The container cap for
the Docker Host is already reached.
Let us assume that the container cap is changed to 12. Now, another
container can be provisioned for image A, as the instance capacity is
not reached yet. However, that does not hold true for image B, as the
instance capacity is set to 5 and already 5 containers are running.
How Container Cap and Instance Capacity is determined
Note
that both container cap and instance capacity is determined by listing
the containers running on the Docker server. It is a common
misunderstanding that this value equals to the number of slaves attached
to the Jenkins instance! However, keep in mind that there may be
containers running, which are not associated to the current Jenkins
instance (because they have been started from another's machine, or they
got decoupled but not cleaned up properly yet, ...)
Triton and Container Cap / Instance Capacity
If your Docker server is running Triton, be aware of the fact that -
in contrast to the Docker reference implementation - containers are
private to the user you are using to log on.
This implies the effect that the container cap and the instance capacity
is calculate relative to the user only and is not applied globally
(which can be a good or a bad thing, depending on your use case).
Known Issues
If you have trouble selecting "Docker" from the clouds list, then you need to update your credentials plugin.
Changelog
See https://github.com/jenkinsci/docker-plugin/blob/master/CHANGELOG.md
Jenkins Docker 插件的更多相关文章
- 第四十四章 微服务CICD(6)- gitlab + jenkins + docker + k8s
总体流程: 在开发机开发代码后提交到gitlab 之后通过webhook插件触发jenkins进行构建,jenkins将代码打成docker镜像,push到docker-registry 之后将在k8 ...
- 从零开始搭建Jenkins+Docker自动化集成环境
本文只简单标记下大概的步骤,具体搭建各个部分的细节,还请自行搜索.第一.二部分只是对Jenkins和Docker的简单介绍,熟悉的同学请直接跳到第三部分. 一.关于Jenkins Jenkins简介 ...
- jenkins+docker 持续构建非docker in docker jenkins docker svn maven
工欲善其事必先利其器,为了解脱程序员的,我们程序员本身发明了很多好用的工具,通过各种工具的组合来达到我们想要的结果 本文采用jenkins docker svn maven作为相关工具,项目sprin ...
- Jenkins + Docker 持续集成
Jenkins介绍 Jenkins是一个开源软件项目,是基于Java开发的一种持续集成工具,用于监控持续重复的工作,旨在提供一个开放易用的软件平台,使软件的持续集成变成可能. 安装部署Jenkins ...
- jenkins+docker 持续构建非docker in docker
工欲善其事必先利其器,为了解脱程序员的,我们程序员本身发明了很多好用的工具,通过各种工具的组合来达到我们想要的结果 本文采用jenkins docker svn maven作为相关工具,项目sprin ...
- node项目自动化部署--基于Jenkins,Docker,Github(1)安装Jenkins
前言 每次项目代码更新后都要重新部署,如果只有一台服务器还好. 但是如果是分布式系统,动不动就很多台服务器,所以代码的自动部署就显得十分重要了. 这里用几篇文章来记录一下如何使用Jenkins,Doc ...
- Jenkins+docker自动部署
项目目录结构如下 对此项目,使用Jenkins构建dockers镜像 步骤如下: 1.安装Jenkins和docker,具体安装步骤,自行度娘把,在此不详述了. 2.Jenkins安装插件Gradle ...
- 基于 Jenkins+Docker+Git 的CI流程初探
在如今的互联网时代,随着软件开发复杂度的不断提高,软件开发和发布管理也越来越重要.目前已经形成一套标准的流程,最重要的组成部分就是持续集成(Continuous Integration,CI)及持续部 ...
- Jenkins+Docker持续集成
本节内容: Jenkins介绍 安装部署Jenkins Jenkins构建maven风格的job Jenkins邮件通知设置 Sonar Jenkins与Docker结合 一.Jenkins介绍 Je ...
随机推荐
- python实现websocket
# websocket实现原理 ''' 1.服务端开启socket,监听ip和端口 2.客户端发送连接请求(带上ip和端口) 3.服务端允许连接 4.客户端生成一个随机字符串,和magic strin ...
- Mongodb的使用(上)
简介 MongoDB 是一个基于分布式 文件存储的NoSQL数据库 由C++语言编写,运行稳定,性能高 旨在为 WEB 应用提供可扩展的高性能数据存储解决方案 查看官方网站 MongoDB特点 模式自 ...
- MVC5 WebAPI 跨域处理
问题描述: 在使用ASP.NET的MVC5进行WebAPI开发的时候,在跨域的情况下会报跨域的错, No 'Access-Control-Allow-Origin' header is present ...
- J.U.C并发框架源码阅读(十六)FutureTask
基于版本jdk1.7.0_80 java.util.concurrent.FutureTask 代码如下 /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is su ...
- 计蒜客 28202. Failing Components-最短路(Dijkstra) (BAPC 2014 Preliminary ACM-ICPC Asia Training League 暑假第一阶段第一场 B)
B. Failing Components 传送门 题意就是单向图,从起点开始找最短路,然后统计一下个数就可以.方向是从b到a,权值为s. 直接最短路跑迪杰斯特拉,一开始用数组版的没过,换了一个队列版 ...
- 蓝桥杯模拟赛 引爆炸弹-并查集+DFS
引爆炸弹 在一个 n×m的方格地图上,某些方格上放置着炸弹.手动引爆一个炸弹以后,炸弹会把炸弹所在的行和列上的所有炸弹引爆,被引爆的炸弹又能引爆其他炸弹,这样连锁下去. 现在为了引爆地图上的所有炸弹, ...
- Python的程序结构[1] -> 方法/Method[3] -> 魔术方法 __getattr__ 与代理模式
__getattr__ 方法 __getattr__ 方法当对象调用内部属性(包括方法等)且未找到对应属性的时候会调用的特殊方法.利用这一特性,可是对函数实现一个代理模式. __getattr__方法 ...
- 洛谷 P3804 后缀自动机
题目描述 给定一个只包含小写字母的字符串SS , 请你求出 SS 的所有出现次数不为 11 的子串的出现次数乘上该子串长度的最大值. 输入输出格式 输入格式: 一行一个仅包含小写字母的字符串SS 输出 ...
- 详细解析ASP.NET中Request接收参数乱码原理
起因:今天早上被同事问了一个问题:说接收到的参数是乱码,让我帮着解决一下. 实际情景: 同事负责的平台是Ext.js框架搭建的,web.config配置文件里配置了全局为“GB2312”编码: < ...
- ubuntu10.10编译TQ2440的x86-qtopia-2.2.0具体问题总结及原因分析
转: http://blog.csdn.net/zyxlinux888/article/details/6705481 http://www.cnblogs.com/liu_xf/archive/20 ...