Getting Started with Jenkins using Docker
$ docker run --user root --privileged -p 8080:8080 -p 50000:50000 -v /path/to/host/volume:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkins
Lets break it down.
-p 8080:8080
What we’re doing here is to expose the Jenkins port on the container out to the host. Jenkins uses 8080 by default so you may want to change the host port to a port that you find comfortable.
-p 50000:50000
Jenkins uses port 50000 for its REST API. Expose this too. This is for Jenkins slave agents to connect.
-v /path/to/host/volume:/var/jenkins_home
Because we want to make sure that we are able to back up our own Jenkins configurations and that we don’t hit the 10GB Devicemapper limit, we should keep most data outside of the container. /var/jenkins_home
is the JENKINS_ROOT path.
-v /var/run/docker.sock:/var/run/docker.sock
is to ensure you don’t go into a Docker-in-Docker situation. Let the container Jenkins use the host Docker.
Backup Regime
Now all you need to do is to backup your /path/to/host/volume
and your jenkins_home information is stored forever in posterity.