Getting started with Jenkins & Docker. Part II: Configure Jenkins via docker image
If you don’t have Docker installed on your local machine, then please follow the instructions from Part I
Starting with Jenkins by downloading its Docker image
This is the Jenkins official docker image:
Execute:
docker pull jenkins/jenkins
Once we have the jenkins image, we need to create a volume to persist our changes:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins
This will store the workspace in /var/jenkins_home. All Jenkins data lives in there (including plugins and configuration). The command above will automatically create a ‘jenkins_home’ docker volume on the host machine, that will survive the container stop/restart/deletion.
As is possible to see, the logs prints a message stating is necessary to make an initial setup. If you lost the generated password, you can find it on /var/jenkins_home/secrets/initialAdminPassword
To find the generated password, you need to:
- Obtain the container id:
docker ps
- To execute the following in order to run commands inside the running docker container:
docker exec -i -t <container_id> /bin/bash
- Once you’re inside the docker shell, then you can see the password generated by executing:
jenkins@<container_id>:/$ cat /var/jenkins_home/secrets/initialAdminPassword
- For getting out of the docker terminal you just need to execute: ctrl + d
- Now, you can go to localhost:8080 and you’ll find the jenkins dashboard with the initial page requesting for the password:
The following page will ask you to add plugins. There will be 02 options: default or you to select some of them. If you select the default option, then Jenkins will install automatically the default plugins.
Once it’s over, Jenkins will ask you to set an admin user:
Everytime you want to initiate Jenkins, you only need to execute:
docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins
In Part III, we show how to reset the admin password of your Jenkins (in case you lost it)