| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 1 | # Official Jenkins Docker image |
| Michael Neale | 2dedbdb | 2014-07-09 16:58:10 +1000 | [diff] [blame] | 2 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 3 | The Jenkins Continuous Integration and Delivery server. |
| Michael Neale | 711e12e | 2014-07-16 11:02:46 +1000 | [diff] [blame] | 4 | |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 5 | This is a fully functional Jenkins server, based on the Long Term Support release |
| 6 | http://jenkins-ci.org/ |
| Michael Neale | 711e12e | 2014-07-16 11:02:46 +1000 | [diff] [blame] | 7 | |
| Michael Neale | 71eb3ab | 2014-07-09 18:04:01 +1000 | [diff] [blame] | 8 | |
| Michael Neale | 00190fb | 2014-07-18 15:17:18 +1000 | [diff] [blame] | 9 | <img src="http://jenkins-ci.org/sites/default/files/jenkins_logo.png"/> |
| 10 | |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 11 | |
| 12 | # Usage |
| Michael Neale | 71eb3ab | 2014-07-09 18:04:01 +1000 | [diff] [blame] | 13 | |
| 14 | ``` |
| Carlos Sanchez | 67b0ff5 | 2015-07-02 12:13:49 +0200 | [diff] [blame^] | 15 | docker run -p 8080:8080 -p 50000:50000 jenkins |
| Michael Neale | 71eb3ab | 2014-07-09 18:04:01 +1000 | [diff] [blame] | 16 | ``` |
| 17 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 18 | This will store the workspace in /var/jenkins_home. All Jenkins data lives in there - including plugins and configuration. |
| 19 | You will probably want to make that a persistent volume (recommended): |
| Michael Neale | 71eb3ab | 2014-07-09 18:04:01 +1000 | [diff] [blame] | 20 | |
| 21 | ``` |
| Carlos Sanchez | 67b0ff5 | 2015-07-02 12:13:49 +0200 | [diff] [blame^] | 22 | docker run -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins |
| Michael Neale | 71eb3ab | 2014-07-09 18:04:01 +1000 | [diff] [blame] | 23 | ``` |
| 24 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 25 | This will store the jenkins data in /your/home on the host. |
| Nicolas De Loof | 3d78499 | 2014-11-28 10:15:15 +0100 | [diff] [blame] | 26 | Ensure that /your/home is accessible by the jenkins user in container (jenkins user - uid 1000). |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 27 | |
| 28 | |
| 29 | You can also use a volume container: |
| 30 | |
| 31 | ``` |
| Carlos Sanchez | 67b0ff5 | 2015-07-02 12:13:49 +0200 | [diff] [blame^] | 32 | docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 33 | ``` |
| 34 | |
| 35 | Then myjenkins container has the volume (please do read about docker volume handling to find out more). |
| 36 | |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 37 | ## Backing up data |
| 38 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 39 | If you bind mount in a volume - you can simply back up that directory |
| 40 | (which is jenkins_home) at any time. |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 41 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 42 | This is highly recommended. Treat the jenkins_home directory as you would a database - in Docker you would generally put a database on a volume. |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 43 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 44 | If your volume is inside a container - you can use ```docker cp $ID:/var/jenkins_home``` command to extract the data. |
| 45 | Note that some symlinks on some OSes may be converted to copies (this can confuse jenkins with lastStableBuild links etc) |
| 46 | |
| 47 | # Attaching build executors |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 48 | |
| rhels | 9aa8840 | 2015-06-01 17:12:25 -0700 | [diff] [blame] | 49 | You can run builds on the master (out of the box) but if you want to attach build slave servers: make sure you map the port: ```-p 50000:50000``` - which will be used when you connect a slave agent. |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 50 | |
| Michael Neale | 2627b96 | 2014-07-21 15:52:23 +1000 | [diff] [blame] | 51 | <a href="https://registry.hub.docker.com/u/maestrodev/build-agent/">Here</a> is an example docker container you can use as a build server with lots of good tools installed - which is well worth trying. |
| 52 | |
| Nicolas De Loof | 28d0c59 | 2014-10-01 15:07:26 +0200 | [diff] [blame] | 53 | # Passing JVM parameters |
| 54 | |
| 55 | You might need to customize the JVM running Jenkins, typically to pass system properties or tweak heap memory settings. Use JAVA_OPTS environment |
| 56 | variable for this purpose : |
| 57 | |
| 58 | ``` |
| Carlos Sanchez | 67b0ff5 | 2015-07-02 12:13:49 +0200 | [diff] [blame^] | 59 | docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS=-Dhudson.footerURL=http://mycompany.com jenkins |
| Nicolas De Loof | 28d0c59 | 2014-10-01 15:07:26 +0200 | [diff] [blame] | 60 | ``` |
| 61 | |
| Nicolas De Loof | b32f552 | 2014-10-06 23:05:56 +0200 | [diff] [blame] | 62 | # Passing Jenkins launcher parameters |
| 63 | |
| 64 | Argument you pass to docker running the jenkins image are passed to jenkins launcher, so you can run for sample : |
| 65 | ``` |
| 66 | docker run jenkins --version |
| 67 | ``` |
| 68 | This will dump Jenkins version, just like when you run jenkins as an executable war. |
| 69 | |
| 70 | You also can define jenkins arguments as `JENKINS_OPTS`. This is usefull to define a set of arguments to pass to jenkins launcher as you |
| 71 | define a derived jenkins image based on the official one with some customized settings. The following sample Dockerfile uses this option |
| 72 | to force use of HTTPS with a certificate included in the image |
| 73 | |
| 74 | ``` |
| 75 | FROM jenkins:1.565.3 |
| 76 | |
| 77 | COPY https.pem /var/lib/jenkins/cert |
| 78 | COPY https.key /var/lib/jenkins/pk |
| 79 | ENV JENKINS_OPTS --httpPort=-1 --httpsPort=8083 --httpsCertificate=/var/lib/jenkins/cert --httpsPrivateKey=/var/lib/jenkins/pk |
| 80 | EXPOSE 8083 |
| 81 | ``` |
| 82 | |
| Michael Neale | 457a91c | 2014-09-26 20:53:22 +1000 | [diff] [blame] | 83 | # Installing more tools |
| 84 | |
| Yaroslav Halchenko | a7e4406 | 2015-03-05 12:37:01 -0500 | [diff] [blame] | 85 | You can run your container as root - and install via apt-get, install as part of build steps via jenkins tool installers, or you can create your own Dockerfile to customise, for example: |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 86 | |
| Michael Neale | 83e5d48 | 2014-09-28 13:14:25 +1000 | [diff] [blame] | 87 | ``` |
| 88 | FROM jenkins |
| starandtina | 1dd04e5 | 2015-03-07 09:35:27 +0800 | [diff] [blame] | 89 | # if we want to install via apt |
| 90 | USER root |
| Christophe Labouisse | 83e3548 | 2014-11-19 18:06:28 +0100 | [diff] [blame] | 91 | RUN apt-get update && apt-get install -y ruby make more-thing-here |
| Michael Neale | 83e5d48 | 2014-09-28 13:14:25 +1000 | [diff] [blame] | 92 | USER jenkins # drop back to the regular jenkins user - good practice |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 93 | ``` |
| 94 | |
| 95 | In such a derived image, you can customize your jenkins instance with hook scripts or additional plugins. |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 96 | For this purpose, use `/usr/share/jenkins/ref` as a place to define the default JENKINS_HOME content you |
| 97 | wish the target installation to look like : |
| Michael Neale | 83e5d48 | 2014-09-28 13:14:25 +1000 | [diff] [blame] | 98 | |
| 99 | ``` |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 100 | FROM jenkins |
| Carlos Sanchez | 11fd2a0 | 2015-04-23 18:03:23 -0700 | [diff] [blame] | 101 | COPY plugins.txt /usr/share/jenkins/ref/ |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 102 | COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy |
| Carlos Sanchez | 11fd2a0 | 2015-04-23 18:03:23 -0700 | [diff] [blame] | 103 | RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 104 | ``` |
| 105 | |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 106 | When jenkins container starts, it will check JENKINS_HOME has this reference content, and copy them there if required. It will not override such files, so if you upgraded some plugins from UI they won't be reverted on next start. |
| 107 | |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 108 | Also see [JENKINS-24986](https://issues.jenkins-ci.org/browse/JENKINS-24986) |
| 109 | |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 110 | For your convenience, you also can use a plain text file to define plugins to be installed (using core-support plugin format) |
| 111 | ``` |
| 112 | pluginID:version |
| 113 | anotherPluginID:version |
| 114 | ``` |
| 115 | And in derived Dockerfile just invoke the utility plugin.sh script |
| 116 | ``` |
| 117 | FROM jenkins |
| 118 | COPY plugins.txt /usr/share/jenkins/plugins.txt |
| 119 | RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt |
| 120 | ``` |
| 121 | |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 122 | |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 123 | # Upgrading |
| 124 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 125 | All the data needed is in the /var/jenkins_home directory - so depending on how you manage that - depends on how you upgrade. Generally - you can copy it out - and then "docker pull" the image again - and you will have the latest LTS - you can then start up with -v pointing to that data (/var/jenkins_home) and everything will be as you left it. |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 126 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 127 | As always - please ensure that you know how to drive docker - especially volume handling! |
| Michael Neale | 709841c | 2014-07-14 12:16:58 +1000 | [diff] [blame] | 128 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 129 | # Questions? |
| Michael Neale | 709841c | 2014-07-14 12:16:58 +1000 | [diff] [blame] | 130 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 131 | Jump on irc.freenode.net and the #jenkins room. Ask! |