实战练习通过docker部署jenkins

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实战练习通过docker部署jenkins相关的知识,希望对你有一定的参考价值。

jenkins官网 :https://jenkins.io/

技术分享
拉取jenkins   

Official Jenkins Docker image


  1. [[email protected]-172-31-16-58 ec2-user]# docker pull jenkins/jenkins
  2. Using default tag: latest
  3. latest: Pulling from jenkins/jenkins
  4. 06b22ddb1913: Pull complete
  5. 336c28b408ed: Pull complete
  6. 1f3e6b8d80c3: Pull complete
  7. 5ccc640979f6: Pull complete
  8. 14eaa20184e6: Pull complete
  9. 19a8522e2399: Pull complete
  10. 39ba9d7befca: Pull complete
  11. 1f81f3143db2: Pull complete
  12. 2034c15120cd: Pull complete
  13. cb9c7784507a: Pull complete
  14. 160eb3637188: Pull complete
  15. 6f0079684645: Pull complete
  16. d03cc51cd013: Pull complete
  17. 5c83a5102435: Pull complete
  18. d1615ed88d09: Pull complete
  19. 184c2f70a0cf: Pull complete
  20. 468b123e967f: Pull complete
  21. f1ae15a4cfc0: Pull complete
  22. 02f7a795bd75: Pull complete
  23. bdac05821dbe: Pull complete
  24. Digest: sha256:30f648f79d447aab092a1a8a2025ee90e257fc03245796a89fb8ffac638259ee
  25. Status: Downloaded newer image for jenkins/jenkins:latest

操作手册:
https://github.com/jenkinsci/docker/blob/master/README.md


  1. docker run 命令详细文档
  2. [[email protected]-172-31-16-58 ec2-user]# docker run --help
  3. Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
  4. Run a command in a new container
  5. Options:
  6. --add-host list Add a custom host-to-IP mapping (host:ip) (default [])
  7. -a, --attach list Attach to STDIN, STDOUT or STDERR (default [])
  8. --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
  9. --blkio-weight-device weighted-device Block IO weight (relative device weight) (default [])
  10. --cap-add list Add Linux capabilities (default [])
  11. --cap-drop list Drop Linux capabilities (default [])
  12. --cgroup-parent string Optional parent cgroup for the container
  13. --cidfile string Write the container ID to the file
  14. --cpu-count int CPU count (Windows only)
  15. --cpu-percent int CPU percent (Windows only)
  16. --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period
  17. --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota
  18. --cpu-rt-period int Limit CPU real-time period in microseconds
  19. --cpu-rt-runtime int Limit CPU real-time runtime in microseconds
  20. -c, --cpu-shares int CPU shares (relative weight) //用于给运行在容器中的所有进程分配CPU的shares值。这是一个相对权重,实际的处理速度还与宿主机CPU相关
  21. --cpus decimal Number of CPUs (default 0.000)
  22. --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1)
  23. --cpuset-mems string MEMs in which to allow execution (0-3, 0,1)
  24. --credentialspec string Credential spec for managed service account (Windows only)
  25. -d, --detach Run container in background and print container ID
  26. --detach-keys string Override the key sequence for detaching a container
  27. --device list Add a host device to the container (default [])
  28. --device-read-bps throttled-device Limit read rate (bytes per second) from a device (default [])
  29. --device-read-iops throttled-device Limit read rate (IO per second) from a device (default [])
  30. --device-write-bps throttled-device Limit write rate (bytes per second) to a device (default [])
  31. --device-write-iops throttled-device Limit write rate (IO per second) to a device (default [])
  32. --disable-content-trust Skip image verification (default true)
  33. --dns list Set custom DNS servers (default [])
  34. --dns-option list Set DNS options (default [])
  35. --dns-search list Set custom DNS search domains (default [])
  36. --entrypoint string Overwrite the default ENTRYPOINT of the image
  37. -e, --env list Set environment variables (default [])
  38. --env-file list Read in a file of environment variables (default [])
  39. --expose list Expose a port or a range of ports (default [])
  40. --group-add list Add additional groups to join (default [])
  41. --health-cmd string Command to run to check health
  42. --health-interval duration Time between running the check (ns|us|ms|s|m|h) (default 0s)
  43. --health-retries int Consecutive failures needed to report unhealthy
  44. --health-timeout duration Maximum time to allow one check to run (ns|us|ms|s|m|h) (default 0s)
  45. --help Print usage
  46. -h, --hostname string Container host name
  47. --init Run an init inside the container that forwards signals and reaps processes
  48. --init-path string Path to the docker-init binary
  49. -i, --interactive Keep STDIN open even if not attached //保持输入打开即使不连接 即选择交互模式,始终保持输入流开放
  50. --io-maxbandwidth string Maximum IO bandwidth limit for the system drive (Windows only)
  51. --io-maxiops uint Maximum IOps limit for the system drive (Windows only)
  52. --ip string Container IPv4 address (e.g. 172.30.100.104)
  53. --ip6 string Container IPv6 address (e.g. 2001:db8::33)
  54. --ipc string IPC namespace to use
  55. --isolation string Container isolation technology
  56. --kernel-memory string Kernel memory limit
  57. -l, --label list Set meta data on a container (default [])
  58. --label-file list Read in a line delimited file of labels (default [])
  59. --link list Add link to another container (default [])
  60. --link-local-ip list Container IPv4/IPv6 link-local addresses (default [])
  61. --log-driver string Logging driver for the container
  62. --log-opt list Log driver options (default [])
  63. --mac-address string Container MAC address (e.g. 92:d0:c6:0a:29:33)
  64. -m, --memory string Memory limit //限制容器为所有进程分配的内存总量
  65. --memory-reservation string Memory soft limit
  66. --memory-swap string Swap limit equal to memory plus swap: ‘-1‘ to enable unlimited swap
  67. --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1)
  68. --name string Assign a name to the container
  69. --network string Connect a container to a network (default "default")
  70. --network-alias list Add network-scoped alias for the container (default [])
  71. --no-healthcheck Disable any container-specified HEALTHCHECK
  72. --oom-kill-disable Disable OOM Killer
  73. --oom-score-adj int Tune host‘s OOM preferences (-1000 to 1000)
  74. --pid string PID namespace to use
  75. --pids-limit int Tune container pids limit (set -1 for unlimited)
  76. --privileged Give extended privileges to this container
  77. -p, --publish list Publish a container‘s port(s) to the host (default []) //端口映射到本机 将容器的端口暴漏给宿主机的端口
  78. -P, --publish-all Publish all exposed ports to random ports
  79. --read-only Mount the container‘s root filesystem as read only
  80. --restart string Restart policy to apply when a container exits (default "no")
  81. --rm Automatically remove the container when it exits
  82. --runtime string Runtime to use for this container
  83. --security-opt list Security Options (default [])
  84. --shm-size string Size of /dev/shm, default value is 64MB
  85. --sig-proxy Proxy received signals to the process (default true)
  86. --stop-signal string Signal to stop a container, SIGTERM by default (default "SIGTERM")
  87. --stop-timeout int Timeout (in seconds) to stop a container
  88. --storage-opt list Storage driver options for the container (default [])
  89. --sysctl map Sysctl options (default map[])
  90. --tmpfs list Mount a tmpfs directory (default [])
  91. -t, --tty Allocate a pseudo-TTY //分配一个伪终端,一般两个参数结合是使用 -it,就可以在容器中利用打开的伪终端进行交互操作
  92. --ulimit ulimit Ulimit options (default [])
  93. -u, --user string Username or UID (format: <name|uid>[:<group|gid>])
  94. --userns string User namespace to use
  95. --uts string UTS namespace to use
  96. -v, --volume list Bind mount a volume (default []) //用户挂载一个volume 可以用多个-v挂载读个 。volume的格式为[host-dir]:[container-dir]:[rw|ro]
  97. --volume-driver string Optional volume driver for the container
  98. --volumes-from list Mount volumes from the specified container(s) (default [])
  99. -w, --workdir string Working directory inside the container
注释:volume:
LVM几个基本概念
*物理存储介质(PhysicalStorageMedia):指系统的物理存储设备:磁盘,如:/dev/hda、/dev/sda等,是存储系统最底层的存储单元
*物理卷(Physical Volume,PV):指磁盘分区或从逻辑上与磁盘分区具有同样功能的设备(如RAID),是LVM的基本存储逻辑块,但和基本的物理存储介质(如分区、磁盘等)比较,却包含有与LVM相关的管理参数。
*物理块(Physical Extent,PE):每一个物理卷PV被划分为称为PE(Physical Extents)的基本单元,具有唯一编号的PE是可以被LVM寻址的最小单元。PE的大小是可配置的,默认为4MB。所以物理卷(PV)由大小等同的基本单元PE组成。
*卷组(Volume Group,VG):类似于非LVM系统中的物理磁盘,其由一个或多个物理卷PV组成。可以在卷组上创建一个或多个LV(逻辑卷)。
*逻辑卷(Logical Volume,LV):类似于非LVM系统中的磁盘分区,逻辑卷建立在卷组VG之上。在逻辑卷LV之上可以建立文件系统(比如/home或者/usr等)。
*逻辑块(Logical Extent,LE):逻辑卷LV也被划分为可被寻址的基本单位,称为LE。在同一个卷组中,LE的大小和PE是相同的,并且一一对应。

运行记录 
  1. [[email protected]-172-31-16-58 ec2-user]# docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins
  2. docker: Error response from daemon: driver failed programming external connectivity on endpoint elegant_darwin (1597358b18b14e84246118d59c368cd17fb7eee2928c2e918305ca511bcae754): Error starting userland proxy: listen tcp 0.0.0.0:8080: bind: address already in use.
  3. [[email protected]-172-31-16-58 ec2-user]# docker run -p 8080:8081 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins
  4. docker: Error response from daemon: driver failed programming external connectivity on endpoint frosty_yonath (67bfcad0fa9e58200dbccd10ad69a1939fb70c128ab586dd23fc1608e6f33de7): Error starting userland proxy: listen tcp 0.0.0.0:8080: bind: address already in use.
  5. [[email protected]-172-31-16-58 ec2-user]# docker run -p 8081:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins
  6. Running from: /usr/share/jenkins/jenkins.war
  7. webroot: EnvVars.masterEnvVars.get("JENKINS_HOME")
  8. Jul 25, 2017 8:21:05 AM Main deleteWinstoneTempContents
  9. WARNING: Failed to delete the temporary Winstone file /tmp/winstone/jenkins.war
  10. Jul 25, 2017 8:21:06 AM org.eclipse.jetty.util.log.Log initialized
  11. INFO: Logging initialized @1202ms to org.eclipse.jetty.util.log.JavaUtilLog
  12. Jul 25, 2017 8:21:06 AM winstone.Logger logInternal
  13. INFO: Beginning extraction from war file
  14. Jul 25, 2017 8:21:07 AM org.eclipse.jetty.server.handler.ContextHandler setContextPath
  15. WARNING: Empty contextPath
  16. Jul 25, 2017 8:21:08 AM org.eclipse.jetty.server.Server doStart
  17. INFO: jetty-9.4.z-SNAPSHOT
  18. Jul 25, 2017 8:21:08 AM org.eclipse.jetty.webapp.StandardDescriptorProcessor visitServlet
  19. INFO: NO JSP Support for /, did not find org.eclipse.jetty.jsp.JettyJspServlet
  20. Jul 25, 2017 8:21:08 AM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
  21. INFO: DefaultSessionIdManager workerName=node0
  22. Jul 25, 2017 8:21:08 AM org.eclipse.jetty.server.session.DefaultSessionIdManager doStart
  23. INFO: No SessionScavenger set, using defaults
  24. Jul 25, 2017 8:21:08 AM org.eclipse.jetty.server.session.HouseKeeper startScavenging
  25. INFO: Scavenging every 660000ms
  26. Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME")
  27. Jul 25, 2017 8:21:09 AM org.eclipse.jetty.server.handler.ContextHandler doStart
  28. INFO: Started w[email protected]62e70ea3{/,file:///var/jenkins_home/war/,AVAILABLE}{/var/jenkins_home/war}
  29. Jul 25, 2017 8:21:09 AM org.eclipse.jetty.server.AbstractConnector doStart
  30. INFO: Started [email protected]{HTTP/1.1,[http/1.1]}{0.0.0.0:8080}
  31. Jul 25, 2017 8:21:09 AM org.eclipse.jetty.server.Server doStart
  32. INFO: Started @4942ms
  33. Jul 25, 2017 8:21:09 AM winstone.Logger logInternal
  34. INFO: Winstone Servlet Engine v4.0 running: controlPort=disabled
  35. Jul 25, 2017 8:21:10 AM jenkins.InitReactorRunner$1 onAttained
  36. INFO: Started initialization
  37. Jul 25, 2017 8:21:10 AM jenkins.InitReactorRunner$1 onAttained
  38. INFO: Listed all plugins
  39. Jul 25, 2017 8:21:13 AM jenkins.InitReactorRunner$1 onAttained
  40. INFO: Prepared all plugins
  41. Jul 25, 2017 8:21:13 AM jenkins.InitReactorRunner$1 onAttained
  42. INFO: Started all plugins
  43. Jul 25, 2017 8:21:13 AM jenkins.InitReactorRunner$1 onAttained
  44. INFO: Augmented all extensions
  45. Jul 25, 2017 8:21:15 AM jenkins.InitReactorRunner$1 onAttained
  46. INFO: Loaded all jobs
  47. Jul 25, 2017 8:21:15 AM hudson.model.AsyncPeriodicWork$1 run
  48. INFO: Started Download metadata
  49. Jul 25, 2017 8:21:16 AM jenkins.util.groovy.GroovyHookScript execute
  50. INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-agent-port.groovy
  51. Jul 25, 2017 8:21:16 AM jenkins.InitReactorRunner$1 onAttained
  52. INFO: Completed initialization
  53. Jul 25, 2017 8:21:17 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  54. INFO: Refreshing org.springframework.web.context.support.[email protected]: display name [Root WebApplicationContext]; startup date [Tue Jul 25 08:21:17 UTC 2017]; root of context hierarchy
  55. Jul 25, 2017 8:21:17 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
  56. INFO: Bean factory for application context [org.springframework.web.context.support.[email protected]]: org.springframework.beans.factory.support.[email protected]
  57. Jul 25, 2017 8:21:17 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  58. INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.[email protected]: defining beans [authenticationManager]; root of factory hierarchy
  59. Jul 25, 2017 8:21:18 AM org.springframework.context.support.AbstractApplicationContext prepareRefresh
  60. INFO: Refreshing org.springframework.web.context.support.[email protected]: display name [Root WebApplicationContext]; startup date [Tue Jul 25 08:21:18 UTC 2017]; root of context hierarchy
  61. Jul 25, 2017 8:21:18 AM org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
  62. INFO: Bean factory for application context [org.springframework.web.context.support.[email protected]]: org.springframework.beans.factory.support.[email protected]
  63. Jul 25, 2017 8:21:18 AM org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
  64. INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.[email protected]: defining beans [filter,legacy]; root of factory hierarchy
  65. Jul 25, 2017 8:21:19 AM jenkins.install.SetupWizard init
  66. INFO:
  67. *************************************************************
  68. *************************************************************
  69. *************************************************************
  70. Jenkins initial setup is required. An admin user has been created and a password generated.
  71. Please use the following password to proceed to installation:
  72. 89389c1eefaf48e3a9a7caa94abbc59d
  73. This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
  74. *************************************************************
  75. *************************************************************
  76. *************************************************************
  77. Jul 25, 2017 8:21:23 AM hudson.model.UpdateSite updateData
  78. INFO: Obtained the latest update center data file for UpdateSource default
  79. Jul 25, 2017 8:21:23 AM hudson.model.DownloadService$Downloadable load
  80. INFO: Obtained the updated data file for hudson.tasks.Maven.MavenInstaller
  81. Jul 25, 2017 8:21:25 AM hudson.model.DownloadService$Downloadable load
  82. INFO: Obtained the updated data file for hudson.tools.JDKInstaller
  83. Jul 25, 2017 8:21:25 AM hudson.model.AsyncPeriodicWork$1 run
  84. INFO: Finished Download metadata. 9,840 ms
  85. Jul 25, 2017 8:21:25 AM hudson.model.UpdateSite updateData
  86. INFO: Obtained the latest update center data file for UpdateSource default
  87. Jul 25, 2017 8:21:25 AM hudson.WebAppMain$3 run
  88. INFO: Jenkins is fully up and running
  89. --> setting agent port for jnlp
  90. --> setting agent port for jnlp... done


安装完成


























以上是关于实战练习通过docker部署jenkins的主要内容,如果未能解决你的问题,请参考以下文章

云原生之Docker实战使用Docker部署jenkins持续集成工具

Jenkins与Docker的自动化CI/CD实战

CI/CD技术专题「Jenkins实战系列」如何通过Gitlab对接Jenkins构建提交自动触发部署构建体系指南(上部)

Jenkins践行持续集成与持续部署实战之DevOps详解

SpringCloud+Docker+Jenkins+GitLab+Maven实现自动化构建与部署实战

Jenkins部署Python项目实战