Monday, March 9, 2020

Running Jenkins docker image with local file system mapped

Step 1: Pull down the Jenkins Docker Image from DockerHub: 


       docker pull jenkins/jenkins:latest

Note: You'll get the latest Jenkins image from jenkins/jenkins tag and not the official jenkins repo. Official one at the time when I downloaded was still referring to 2.60.3 version, whereas the jenkins/jenkins one was using 2.224. If you use the older version, certain plugins may not load properly.

Step 2: Create a local volume


       docker volume create jenkins-data

Step 3: Run Jenkins docker image with this local volume mapped to the jenkin container's path. 


      docker run --name jenkins \
           --d \
           -p 49001:8080 \
           -v jenkins-data:/var/jenkins_home \
           jenkins/jenkins:latest

Note: If you run into the following error:

/usr/local/bin/jenkins.sh: line 25: /var/jenkins_home/copy_reference_file.log: Permission denied

You will then need to give the correct permissions to the local directory which will be mapped to the containers path.

      sudo chown 1000 jenkins-data

Finally, when the container starts, you can access Jenkins Home by going to http://localhost:49001
When you access it for the first time, it'll ask for the admin password to be entered, which can be found from the logs or from $JENKINS_HOME/secrets/initialAdminPassword file.

      docker exec jenkins bash -c 'cat $JENKINS_HOME/secrets/initialAdminPassword'

No comments:

Post a Comment