blob: f3bd4814bf6438d802390c0b0e8af49a0e2ee485 [file] [log] [blame] [view]
Michael Neale3e124ed2014-07-18 15:12:27 +10001# Official Jenkins Docker image
Michael Neale2dedbdb2014-07-09 16:58:10 +10002
Michael Nealefe683742014-09-26 20:49:30 +10003The Jenkins Continuous Integration and Delivery server.
Michael Neale711e12e2014-07-16 11:02:46 +10004
Michael Neale3e124ed2014-07-18 15:12:27 +10005This is a fully functional Jenkins server, based on the Long Term Support release
6http://jenkins-ci.org/
Michael Neale711e12e2014-07-16 11:02:46 +10007
Michael Neale71eb3ab2014-07-09 18:04:01 +10008
Michael Neale00190fb2014-07-18 15:17:18 +10009<img src="http://jenkins-ci.org/sites/default/files/jenkins_logo.png"/>
10
Michael Neale3e124ed2014-07-18 15:12:27 +100011
12# Usage
Michael Neale71eb3ab2014-07-09 18:04:01 +100013
14```
Carlos Sanchez67b0ff52015-07-02 12:13:49 +020015docker run -p 8080:8080 -p 50000:50000 jenkins
Michael Neale71eb3ab2014-07-09 18:04:01 +100016```
17
Michael Nealefe683742014-09-26 20:49:30 +100018This will store the workspace in /var/jenkins_home. All Jenkins data lives in there - including plugins and configuration.
19You will probably want to make that a persistent volume (recommended):
Michael Neale71eb3ab2014-07-09 18:04:01 +100020
21```
Carlos Sanchez67b0ff52015-07-02 12:13:49 +020022docker run -p 8080:8080 -p 50000:50000 -v /your/home:/var/jenkins_home jenkins
Michael Neale71eb3ab2014-07-09 18:04:01 +100023```
24
Carlos Sanchezc8c95d12015-07-02 12:36:13 +020025This will store the jenkins data in `/your/home` on the host.
26Ensure 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 Nealefe683742014-09-26 20:49:30 +100027
28
29You can also use a volume container:
30
31```
Carlos Sanchez67b0ff52015-07-02 12:13:49 +020032docker run --name myjenkins -p 8080:8080 -p 50000:50000 -v /var/jenkins_home jenkins
Michael Nealefe683742014-09-26 20:49:30 +100033```
34
35Then myjenkins container has the volume (please do read about docker volume handling to find out more).
36
Michael Neale3e124ed2014-07-18 15:12:27 +100037## Backing up data
38
Michael Nealefe683742014-09-26 20:49:30 +100039If you bind mount in a volume - you can simply back up that directory
40(which is jenkins_home) at any time.
Michael Neale3e124ed2014-07-18 15:12:27 +100041
Michael Nealefe683742014-09-26 20:49:30 +100042This 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 Neale3e124ed2014-07-18 15:12:27 +100043
Carlos Sanchez40c86cd2015-07-15 19:16:11 +020044If 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 Nealefe683742014-09-26 20:49:30 +100045Note that some symlinks on some OSes may be converted to copies (this can confuse jenkins with lastStableBuild links etc)
46
Carlos Sanchez40c86cd2015-07-15 19:16:11 +020047For more info check Docker docs section on [Managing data in containers](https://docs.docker.com/userguide/dockervolumes/)
48
Carlos Sanchezd6669532015-07-02 12:22:00 +020049# Setting the number of executors
50
51You 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 Croyf1f43982015-10-12 14:18:02 -070053`executors.groovy`
Carlos Sanchezd6669532015-07-02 12:22:00 +020054```
R. Tyler Croyf1f43982015-10-12 14:18:02 -070055import jenkins.model.*
Carlos Sanchezd6669532015-07-02 12:22:00 +020056Jenkins.instance.setNumExecutors(5)
57```
58
59and `Dockerfile`
60
61```
62FROM jenkins
63COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/executors.groovy
64```
65
66
Michael Nealefe683742014-09-26 20:49:30 +100067# Attaching build executors
Michael Neale3e124ed2014-07-18 15:12:27 +100068
rhels9aa88402015-06-01 17:12:25 -070069You 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 Neale3e124ed2014-07-18 15:12:27 +100070
Michael Neale2627b962014-07-21 15:52:23 +100071<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 Loof28d0c592014-10-01 15:07:26 +020073# Passing JVM parameters
74
75You might need to customize the JVM running Jenkins, typically to pass system properties or tweak heap memory settings. Use JAVA_OPTS environment
76variable for this purpose :
77
78```
Carlos Sanchez67b0ff52015-07-02 12:13:49 +020079docker run --name myjenkins -p 8080:8080 -p 50000:50000 --env JAVA_OPTS=-Dhudson.footerURL=http://mycompany.com jenkins
Nicolas De Loof28d0c592014-10-01 15:07:26 +020080```
81
Carlos Sanchezf5a524a2015-08-22 11:33:51 +020082# Configuring logging
83
84Jenkins logging can be configured through a properties file and `java.util.logging.config.file` Java property.
85For example:
86
87```
88mkdir data
89cat > data/log.properties <<EOF
90handlers=java.util.logging.ConsoleHandler
91jenkins.level=FINEST
92java.util.logging.ConsoleHandler.level=FINEST
93EOF
94docker 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 Loofb32f5522014-10-06 23:05:56 +020098# Passing Jenkins launcher parameters
99
100Argument you pass to docker running the jenkins image are passed to jenkins launcher, so you can run for sample :
101```
102docker run jenkins --version
103```
104This will dump Jenkins version, just like when you run jenkins as an executable war.
105
106You also can define jenkins arguments as `JENKINS_OPTS`. This is usefull to define a set of arguments to pass to jenkins launcher as you
107define a derived jenkins image based on the official one with some customized settings. The following sample Dockerfile uses this option
108to force use of HTTPS with a certificate included in the image
109
110```
111FROM jenkins:1.565.3
112
113COPY https.pem /var/lib/jenkins/cert
114COPY https.key /var/lib/jenkins/pk
115ENV JENKINS_OPTS --httpPort=-1 --httpsPort=8083 --httpsCertificate=/var/lib/jenkins/cert --httpsPrivateKey=/var/lib/jenkins/pk
116EXPOSE 8083
117```
118
jeichelaebb8b22015-08-10 12:38:20 -0400119You can also change the default slave agent port for jenkins by defining `JENKINS_SLAVE_AGENT_PORT` in a sample Dockerfile.
120
121```
122FROM jenkins:1.565.3
123ENV JENKINS_SLAVE_AGENT_PORT 50001
124```
125or as a parameter to docker,
126```
127docker run --name myjenkins -p 8080:8080 -p 50001:50001 --env JENKINS_SLAVE_AGENT_PORT=50001 jenkins
128```
129
Michael Neale457a91c2014-09-26 20:53:22 +1000130# Installing more tools
131
Yaroslav Halchenkoa7e44062015-03-05 12:37:01 -0500132You 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 Neale3e124ed2014-07-18 15:12:27 +1000133
Michael Neale83e5d482014-09-28 13:14:25 +1000134```
135FROM jenkins
starandtina1dd04e52015-03-07 09:35:27 +0800136# if we want to install via apt
137USER root
Christophe Labouisse83e35482014-11-19 18:06:28 +0100138RUN apt-get update && apt-get install -y ruby make more-thing-here
Michael Neale83e5d482014-09-28 13:14:25 +1000139USER jenkins # drop back to the regular jenkins user - good practice
Nicolas De Loof91181652014-10-04 08:31:01 +0200140```
141
142In such a derived image, you can customize your jenkins instance with hook scripts or additional plugins.
Nicolas De Loofacb86492014-10-24 13:43:13 +0200143For this purpose, use `/usr/share/jenkins/ref` as a place to define the default JENKINS_HOME content you
144wish the target installation to look like :
Michael Neale83e5d482014-09-28 13:14:25 +1000145
146```
Nicolas De Loofacb86492014-10-24 13:43:13 +0200147FROM jenkins
Carlos Sanchez11fd2a02015-04-23 18:03:23 -0700148COPY plugins.txt /usr/share/jenkins/ref/
Nicolas De Loofacb86492014-10-24 13:43:13 +0200149COPY custom.groovy /usr/share/jenkins/ref/init.groovy.d/custom.groovy
Carlos Sanchez11fd2a02015-04-23 18:03:23 -0700150RUN /usr/local/bin/plugins.sh /usr/share/jenkins/ref/plugins.txt
Nicolas De Loof91181652014-10-04 08:31:01 +0200151```
152
Carlos Sanchez8d8c5292015-09-17 10:01:49 +0200153When jenkins container starts, it will check JENKINS_HOME has this reference content, and copy them
154there if required. It will not override such files, so if you upgraded some plugins from UI they won't
155be reverted on next start.
Nicolas De Loofacb86492014-10-24 13:43:13 +0200156
Nicolas De Loof91181652014-10-04 08:31:01 +0200157Also see [JENKINS-24986](https://issues.jenkins-ci.org/browse/JENKINS-24986)
158
Carlos Sanchez8d8c5292015-09-17 10:01:49 +0200159For your convenience, you also can use a plain text file to define plugins to be installed
160(using core-support plugin format).
161All plugins need to be listed as there is no transitive dependency resolution.
162
Nicolas De Loofacb86492014-10-24 13:43:13 +0200163```
164pluginID:version
Carlos Sanchez8d8c5292015-09-17 10:01:49 +0200165credentials:1.18
166maven-plugin:2.7.1
167...
Nicolas De Loofacb86492014-10-24 13:43:13 +0200168```
Carlos Sanchez8d8c5292015-09-17 10:01:49 +0200169
Nicolas De Loofacb86492014-10-24 13:43:13 +0200170And in derived Dockerfile just invoke the utility plugin.sh script
Carlos Sanchez8d8c5292015-09-17 10:01:49 +0200171
Nicolas De Loofacb86492014-10-24 13:43:13 +0200172```
173FROM jenkins
174COPY plugins.txt /usr/share/jenkins/plugins.txt
175RUN /usr/local/bin/plugins.sh /usr/share/jenkins/plugins.txt
176```
177
Nicolas De Loof91181652014-10-04 08:31:01 +0200178
Michael Neale3e124ed2014-07-18 15:12:27 +1000179# Upgrading
180
Michael Nealefe683742014-09-26 20:49:30 +1000181All 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 Neale3e124ed2014-07-18 15:12:27 +1000182
Michael Nealefe683742014-09-26 20:49:30 +1000183As always - please ensure that you know how to drive docker - especially volume handling!
Michael Neale709841c2014-07-14 12:16:58 +1000184
Michael Nealefe683742014-09-26 20:49:30 +1000185# Questions?
Michael Neale709841c2014-07-14 12:16:58 +1000186
Michael Nealefe683742014-09-26 20:49:30 +1000187Jump on irc.freenode.net and the #jenkins room. Ask!