You should have Docker properly installed on your machine. Check Docker installation guide for details.
First, pull the official jenkins image from Docker repository.
docker pull jenkins
Next, run a container using this image and map data directory from the container to the host; e.g in the example below /var/jenkins_home
from the container is mapped to jenkins/
directory from the current path on the host. Jenkins 8080
port is also exposed to the host as 49001
.
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins/jenkins
Addtionally, you can configure nginx as a reverse proxy to your Jenkins instance, e.g.
upstream app { server 127.0.0.1:49001; } server { listen 80; server_name jenkins.your-domain.com; location / { proxy_pass http://app; } }
11 Comments
Unknown User (sravanb)
I was able to pull image successfully and while I run the image the volume link was working fine too, but the container is dying after some seconds. So I was unable to see jenkins up & running. Any ideas? Thank you!
Unknown User (ralphbean)
Try adding `:z` at the end of the mount like this:$ docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins
That sets the selinux context, which may be incorrect.
Unknown User (eranmark)
How can I set it for persistance, in case docker service is restarted?
Unknown User (lmcdasm)
add --restart=always to the command line
Unknown User (yogen_prasad)
Hi Markus,
For making the Jenkins Configuration persistant , you can just use Docker container volumes.
In you Compose.yml :
volumes:
jenkins_conf:
and under your Jenkins service add volune as :- jenkins_conf:/var/jenkins_home/
Thanks
Unknown User (lub121)
How to update jenkins docker container?
Jenkins in my docker version is Jenkins 2.60.3 and latest update is 2.73.3 ?
Unknown User (jennbriden)
To update your Jenkins instance, just rerun the initial command:
docker pull jenkins
Unknown User (naktinis)
I ran all the commands as provided and I get an error running "docker run ...":
My uid is 1001, but for some reason docker runs it as uid 1000, which is a different user.
I'm running it on ubuntu and it's a pretty standard configuration, so I believe you should at least mention this in this documentation page. Or maybe even consider redesigning the installation procedure somehow.
Unknown User (plamenti)
Hi R Nak,
This works for me:
$ mkdir $PWD/jenkins
$ chown 1000 $PWD/jenkins
docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins
Unknown User (jennbriden)
Also, make sure that Docker is configured to have access to the host volume where you are storing the files. For example, C:\. You can set this in the Docker UI and by CLI.
https://github.com/jenkinsci/docker/blob/master/README.md
Unknown User (jcamilli)
Here's a script to start Jenkins ...