Skip to end of metadata
Go to start of metadata

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

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;
    }
}
  • No labels

10 Comments

  1. 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!

    1. 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.

  2. How can I set it for persistance, in case docker service is restarted?

    1. add --restart=always to the command line

       

  3. 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

     

  4. How to update jenkins docker container?
    Jenkins in my docker version is Jenkins 2.60.3  and latest update is 2.73.3 ?

    1. To update your Jenkins instance, just rerun the initial command:

      docker pull jenkins

  5. I ran all the commands as provided and I get an error running "docker run ...":

    touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied
    Can not write to /var/jenkins_home/copy_reference_file.log. Wrong volume permissions?

    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.

    1. Hi R Nak,

      This works for me:

      1. Prepare the volume directory:
        $ mkdir $PWD/jenkins
      2. The directory need to be separated with the admin ownership to keep the Jenkins home:
        $ chown 1000 $PWD/jenkins
      3. Now run the command from the example:
        docker run -d -p 49001:8080 -v $PWD/jenkins:/var/jenkins_home:z -t jenkins
    2. 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