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 ...
随机推荐
- BigDecimal 使用 静态方法总结
转自:http://myrecord.top/?post=18 -------------千位加, public static String getQs(String old){ boolean re ...
- js-监听页面滚动
两种监听页面滚动的方法 一.原生js通过window.onscroll监听 window.onscroll = function() { //为了保证兼容性,这里取两个值,哪个有值取哪一个 //scr ...
- UVA 11149.Power of Matrix-矩阵快速幂倍增
Power of Matrix UVA - 11149 代码: #include <cstdio> #include <cstring> #include < ...
- SQL DISTINCT 用法(去重)
现在以下数据 查有出现的TeacherId SELECT TeacherID FROM Student 结果 有重复的ID出现 确实查法: SELECT TeacherID FROM Student ...
- hdu 1500 Chopsticks DP
题目链接:HDU - 1500 In China, people use a pair of chopsticks to get food on the table, but Mr. L is a b ...
- 使用net包发送http请求
[java] view plain copy import java.io.BufferedReader; import java.io.InputStream; import java.io.Inp ...
- linux-启动脚本-souce与sh
source: 在当前shell程序中执行, 因此当前shell程序中的变量和环境变量,均可见. 执行的脚本,能更新到当前shell程序. sh: 开启一个新 ...
- What is Mocking?
Mocking is primarily used in unit testing. An object under test may have dependencies on other (comp ...
- Android background tint颜色渲染
该篇文章主要是讲Android颜色渲染,首先先来看看PorterDuff,对绘图非常重要. PorterDuff的由来: 相信大多数人看到这个ProterDuff单词很奇怪了吧,这肿么个意思呢,然后就 ...
- HTML5 资源导航
1,百度百科 http://baike.baidu.com/view/951383.htm 2,w3school http://www.w3school.com.cn/html5/ 3, HTML5 ...