设为首页 收藏本站
查看: 600|回复: 0

[经验分享] Jenkins Docker 插件

[复制链接]

尚未签到

发表于 2018-1-8 13:36:37 | 显示全部楼层 |阅读模式
Plugin Information

  Plugin>  docker-plugin
  Changes

  In Latest>
  
Since Latest>  Latest> Latest> Required Core
Dependencies
  0.16.2 (archives)
Sep 13, 2016
1.625.3
ssh-slaves (version:1.6)
token-macro (version:1.7, optional)
durable-task (version:1.3)
  Source Code
Issue Tracking
Pull Requests
Maintainer(s)
  GitHub
Open Issues
Pull Requests
Kanstantsin Shautsou (id: KostyaSha)
  
Nigel Magnay (id: magnayn)
  Usage

  Installations
  2016-Aug 4517
  
2016-Sep 4838
  
2016-Oct 4946
  
2016-Nov 5159
  
2016-Dec 5150
  
2017-Jan 5600
  
2017-Feb 5711
  
2017-Mar 6336
  
2017-Apr 6412
  
2017-May 6922
  
2017-Jun 7052
  
2017-Jul 7200
  


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>
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>  
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>  
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>
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>
For a detailed discussion on Container Caps and Instance Capacity, please read the section "Container Cap and Instance Capacity" below.


Note: Technically, this is implemented differently: When trying to start
a new container, the system checks the number of associated
computers/slaves (also counting slaves which are not associated with
this plugin) and checks it against this value of Container Cap.

If the number of computers is higher than this cap, no new container is provisioned (see also JENKINS-36920)
  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>
For a detailed discussion on Container Caps and Instance Capacity,  please read the section "Container Cap and Instance Capacity" below.


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
jobs being built using docker containers. Specify the location on the
Jenkins master where the job workspaces will be and map them from the
images using volumes, network shares, etc.
  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

For a detailed discussion on Container Caps and Instance Capacity,  please read the section "Container Cap and Instance Capacity" below.

  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>
  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>
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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-432931-1-1.html 上篇帖子: Jenkins管理静态资源 下篇帖子: Jenkins + Docker 持续集成
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表