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 ...
随机推荐
- input 输入框 光标错位问题 、移动端输入框/input框光标错位问题、微信H5输入框/input框光标错位问题
在IOS系统下的问题: 搜索出的建议如下: 你应该是用fixed定位做的弹出框,弹出框里面有文本框.fixed在ios上兼容不友好,会造成光标乱跳.建议用better-scroll,或者用absolu ...
- hdu 5157(树状数组+Manacher)
Harry and magic string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- nginx安全日志分析脚本的编写
https://blog.csdn.net/nextdoor6/article/details/51914966
- ios控件渐变色的处理
+(CAGradientLayer *)gradientColorWithBounds:(CGRect)bounds startColorHexString:(NSString *)startColo ...
- 使用keytool生成ssl证书
使用keytool生成ssl证书 在项目中由于要使用https访问项目,然后了解到jdk有一个自带的工具keytool可以用来生成ssl证书,从而可以通过https进行访问. 使用keytool生成s ...
- 51nod 1137.矩阵乘法-矩阵乘法
1137 矩阵乘法 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 给出2个N * N的矩阵M1和M2,输出2个矩阵相乘后的结果. Input 第1行:1个数N, ...
- 将C#程序做成服务后服务自动停止的问题
查了好几天,没法调试实在是很难找错误,今天想了半天到事件查看器,提示如下: 说明: 由于未经处理的异常,进程终止. 异常信息: System.NullReferenceException 想了半天,应 ...
- [Python Cookbook] Pandas: Indexing of DataFrame
Selecting a Row df.loc[index] # if index is a string, add ' '; if index is a number, no ' ' or df.il ...
- spark完整的数据倾斜解决方案
1.数据倾斜的原理 2.数据倾斜的现象 3.数据倾斜的产生原因与定位 在执行shuffle操作的时候,大家都知道,我们之前讲解过shuffle的原理. 是按照key,来进行values的数据的输出.拉 ...
- SQL注入漏洞原理
系统中安全性是非常重要的,为了保证安全性很多解决方案被应用到系统中,比如架设防火墙防止数据库服务器直接暴露给外部访问者.使用数据库的授权机制防止未授权的用户访问数据库,这些解决方案可以很大程度上避免了 ...