| 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 | |
| Carlos Sanchez | c8c95d1 | 2015-07-02 12:36:13 +0200 | [diff] [blame] | 25 | This will store the jenkins data in `/your/home` on the host. |
| 26 | Ensure that `/your/home` is accessible by the jenkins user in container (jenkins user - uid 1000) or use `-u some_other_user` parameter with `docker run`. |
| 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 | |
| Carlos Sanchez | 40c86cd | 2015-07-15 19:16:11 +0200 | [diff] [blame] | 44 | If your volume is inside a container - you can use ```docker cp $ID:/var/jenkins_home``` command to extract the data, or other options to find where the volume data is. |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 45 | Note that some symlinks on some OSes may be converted to copies (this can confuse jenkins with lastStableBuild links etc) |
| 46 | |
| Carlos Sanchez | 40c86cd | 2015-07-15 19:16:11 +0200 | [diff] [blame] | 47 | For more info check Docker docs section on [Managing data in containers](https://docs.docker.com/userguide/dockervolumes/) |
| 48 | |
| Carlos Sanchez | d666953 | 2015-07-02 12:22:00 +0200 | [diff] [blame] | 49 | # Setting the number of executors |
| 50 | |
| 51 | You can specify and set the number of executors of your Jenkins master instance using a groovy script. By default its set to 2 executors, but you can extend the image and change it to your desired number of executors : |
| 52 | |
| R. Tyler Croy | f1f4398 | 2015-10-12 14:18:02 -0700 | [diff] [blame^] | 53 | `executors.groovy` |
| Carlos Sanchez | d666953 | 2015-07-02 12:22:00 +0200 | [diff] [blame] | 54 | ``` |
| R. Tyler Croy | f1f4398 | 2015-10-12 14:18:02 -0700 | [diff] [blame^] | 55 | import jenkins.model.* |
| Carlos Sanchez | d666953 | 2015-07-02 12:22:00 +0200 | [diff] [blame] | 56 | Jenkins.instance.setNumExecutors(5) |
| 57 | ``` |
| 58 | |
| 59 | and `Dockerfile` |
| 60 | |
| 61 | ``` |
| 62 | FROM jenkins |
| 63 | COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/executors.groovy |
| 64 | ``` |
| 65 | |
| 66 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 67 | # Attaching build executors |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 68 | |
| rhels | 9aa8840 | 2015-06-01 17:12:25 -0700 | [diff] [blame] | 69 | 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] | 70 | |
| Michael Neale | 2627b96 | 2014-07-21 15:52:23 +1000 | [diff] [blame] | 71 | <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. |
| 72 | |
| Nicolas De Loof | 28d0c59 | 2014-10-01 15:07:26 +0200 | [diff] [blame] | 73 | # Passing JVM parameters |
| 74 | |
| 75 | You might need to customize the JVM running Jenkins, typically to pass system properties or tweak heap memory settings. Use JAVA_OPTS environment |
| 76 | variable for this purpose : |
| 77 | |
| 78 | ``` |
| Carlos Sanchez | 67b0ff5 | 2015-07-02 12:13:49 +0200 | [diff] [blame] | 79 | 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] | 80 | ``` |
| 81 | |
| Carlos Sanchez | f5a524a | 2015-08-22 11:33:51 +0200 | [diff] [blame] | 82 | # Configuring logging |
| 83 | |
| 84 | Jenkins logging can be configured through a properties file and `java.util.logging.config.file` Java property. |
| 85 | For example: |
| 86 | |
| 87 | ``` |
| 88 | mkdir data |
| 89 | cat > data/log.properties <<EOF |
| 90 | handlers=java.util.logging.ConsoleHandler |
| 91 | jenkins.level=FINEST |
| 92 | java.util.logging.ConsoleHandler.level=FINEST |
| 93 | EOF |
| 94 | docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS="-Djava.util.logging.config.file=/var/jenkins_home/log.properties" -v `pwd`/data:/var/jenkins_home jenkins |
| 95 | ``` |
| 96 | |
| 97 | |
| Nicolas De Loof | b32f552 | 2014-10-06 23:05:56 +0200 | [diff] [blame] | 98 | # Passing Jenkins launcher parameters |
| 99 | |
| 100 | Argument you pass to docker running the jenkins image are passed to jenkins launcher, so you can run for sample : |
| 101 | ``` |
| 102 | docker run jenkins --version |
| 103 | ``` |
| 104 | This will dump Jenkins version, just like when you run jenkins as an executable war. |
| 105 | |
| 106 | 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 |
| 107 | define a derived jenkins image based on the official one with some customized settings. The following sample Dockerfile uses this option |
| 108 | to force use of HTTPS with a certificate included in the image |
| 109 | |
| 110 | ``` |
| 111 | FROM jenkins:1.565.3 |
| 112 | |
| 113 | COPY https.pem /var/lib/jenkins/cert |
| 114 | COPY https.key /var/lib/jenkins/pk |
| 115 | ENV JENKINS_OPTS --httpPort=-1 --httpsPort=8083 --httpsCertificate=/var/lib/jenkins/cert --httpsPrivateKey=/var/lib/jenkins/pk |
| 116 | EXPOSE 8083 |
| 117 | ``` |
| 118 | |
| jeichel | aebb8b2 | 2015-08-10 12:38:20 -0400 | [diff] [blame] | 119 | You can also change the default slave agent port for jenkins by defining `JENKINS_SLAVE_AGENT_PORT` in a sample Dockerfile. |
| 120 | |
| 121 | ``` |
| 122 | FROM jenkins:1.565.3 |
| 123 | ENV JENKINS_SLAVE_AGENT_PORT 50001 |
| 124 | ``` |
| 125 | or as a parameter to docker, |
| 126 | ``` |
| 127 | docker run --name myjenkins -p 8080:8080 -p 50001:50001 --env JENKINS_SLAVE_AGENT_PORT=50001 jenkins |
| 128 | ``` |
| 129 | |
| Michael Neale | 457a91c | 2014-09-26 20:53:22 +1000 | [diff] [blame] | 130 | # Installing more tools |
| 131 | |
| Yaroslav Halchenko | a7e4406 | 2015-03-05 12:37:01 -0500 | [diff] [blame] | 132 | 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] | 133 | |
| Michael Neale | 83e5d48 | 2014-09-28 13:14:25 +1000 | [diff] [blame] | 134 | ``` |
| 135 | FROM jenkins |
| starandtina | 1dd04e5 | 2015-03-07 09:35:27 +0800 | [diff] [blame] | 136 | # if we want to install via apt |
| 137 | USER root |
| Christophe Labouisse | 83e3548 | 2014-11-19 18:06:28 +0100 | [diff] [blame] | 138 | 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] | 139 | USER jenkins # drop back to the regular jenkins user - good practice |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 140 | ``` |
| 141 | |
| 142 | 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] | 143 | For this purpose, use `/usr/share/jenkins/ref` as a place to define the default JENKINS_HOME content you |
| 144 | wish the target installation to look like : |
| Michael Neale | 83e5d48 | 2014-09-28 13:14:25 +1000 | [diff] [blame] | 145 | |
| 146 | ``` |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 147 | FROM jenkins |
| Carlos Sanchez | 11fd2a0 | 2015-04-23 18:03:23 -0700 | [diff] [blame] | 148 | COPY plugins.txt /usr/share/jenkins/ref/ |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 149 | COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy |
| Carlos Sanchez | 11fd2a0 | 2015-04-23 18:03:23 -0700 | [diff] [blame] | 150 | 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] | 151 | ``` |
| 152 | |
| Carlos Sanchez | 8d8c529 | 2015-09-17 10:01:49 +0200 | [diff] [blame] | 153 | When jenkins container starts, it will check JENKINS_HOME has this reference content, and copy them |
| 154 | there if required. It will not override such files, so if you upgraded some plugins from UI they won't |
| 155 | be reverted on next start. |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 156 | |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 157 | Also see [JENKINS-24986](https://issues.jenkins-ci.org/browse/JENKINS-24986) |
| 158 | |
| Carlos Sanchez | 8d8c529 | 2015-09-17 10:01:49 +0200 | [diff] [blame] | 159 | For your convenience, you also can use a plain text file to define plugins to be installed |
| 160 | (using core-support plugin format). |
| 161 | All plugins need to be listed as there is no transitive dependency resolution. |
| 162 | |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 163 | ``` |
| 164 | pluginID:version |
| Carlos Sanchez | 8d8c529 | 2015-09-17 10:01:49 +0200 | [diff] [blame] | 165 | credentials:1.18 |
| 166 | maven-plugin:2.7.1 |
| 167 | ... |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 168 | ``` |
| Carlos Sanchez | 8d8c529 | 2015-09-17 10:01:49 +0200 | [diff] [blame] | 169 | |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 170 | And in derived Dockerfile just invoke the utility plugin.sh script |
| Carlos Sanchez | 8d8c529 | 2015-09-17 10:01:49 +0200 | [diff] [blame] | 171 | |
| Nicolas De Loof | acb8649 | 2014-10-24 13:43:13 +0200 | [diff] [blame] | 172 | ``` |
| 173 | FROM jenkins |
| 174 | COPY plugins.txt /usr/share/jenkins/plugins.txt |
| 175 | RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt |
| 176 | ``` |
| 177 | |
| Nicolas De Loof | 9118165 | 2014-10-04 08:31:01 +0200 | [diff] [blame] | 178 | |
| Michael Neale | 3e124ed | 2014-07-18 15:12:27 +1000 | [diff] [blame] | 179 | # Upgrading |
| 180 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 181 | 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] | 182 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 183 | 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] | 184 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 185 | # Questions? |
| Michael Neale | 709841c | 2014-07-14 12:16:58 +1000 | [diff] [blame] | 186 | |
| Michael Neale | fe68374 | 2014-09-26 20:49:30 +1000 | [diff] [blame] | 187 | Jump on irc.freenode.net and the #jenkins room. Ask! |