Guide to Installing Jenkins using Docker — DevOps01
Jenkins is one of the most popular continuous integration tool that helps developers to automatically build and test code changes, and then deploy them into production. Jenkins helps to automate the software development process, and can be used to monitor the execution of external programs and trigger events such as building a new version of a software program or deploying a new application into production.
In this particular article you will learn how you can install Jenkins using Docker in your machine.
Prerequisites
You should have Docker installed on your machine in order to follow along with this post. You don’t need to be an expert on Docker; just being familiar with a few fundamental commands will do.
If you don’t have docker installed then you can follow this guide to install docker in your system.
Step 1 — Understanding Docker Pull/Run
You receive a docker CLI tool on your terminal once Docker is installed. Any image from the Docker Hub can be downloaded and launched using this CLI during Docker runtime
While the docker run
command can be used to create running containers, docker pull
just pulls an image from the repository. In this article, you will launch Jenkins using the docker run command.
Step 2 — Running Docker Run Command
After opening your terminal type the following command to install Jenkins as a container in Docker.
$ docker run -p 8080:8080 -p 50000:50000 -d -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
After executing the above command, it will produce the following output.
After successful installation you can run docker ps
command to confirm that jenkins container is running in your machine. Before going any further lets breakdown the command we ran on the terminal.
You can see from the command above that we downloaded Jenkins from a remote repository using docker run and then turned it into a container. Jenkins runs by default on port 8080, thus we bound port 8080 to our local machine, which is why the -p 8080:8080
is present. The second port -p 50000:50000
is for the master and worker nodes of Jenkins; while we don’t need this port for this tutorial, Jenkins requires it. The -d
flag instructs Docker to continue operating the container even if the terminal is closed. It stands for detach mode. The flag-v jenkins_home:/var/jenkins_home
is used to specify the volume in docker. This is used to persist all the jobs that we define on the constainer even when we stop the container.
Step 3 — Working in the UI
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3f32d437b011 jenkins/jenkins:lts "/usr/bin/tini -- /u…" 3 minutes ago Up 3 minutes 0.0.0.0:8080->8080/tcp, 0.0.0.0:50000->50000/tcp modest_pare
Once you see the above ouput after running docker ps
, goto localhost:8080
in your browser to sign into Jenkins UI.
You must input the Admin Password stored in the docker volumes you just defined on the screen above. Go to the terminal and perform the following steps to access the password.
$ docker exec -it 3f32d437b011 bash
jenkins@3f32d437b011:/$ cat /var/jenkins_home/secrets/initialAdminPassword
6998f4fee3cf49389ce53c52c0334a67
jenkins@3f32d437b011:/$
In the above command you started an interactive bash in the Jenkins Container using exec
command with -it flag
. Note that Container ID3f32d437b011
would be different in your system. You can check your ID using docker ps
command.
After installing the recommended plugins, the jenkins UI will show a form to create a user, just fill in the the details and click on Save and Continue. After clicking Start Jenkins in the Next screen, you will see the first look at Jenkins Dashboard.
From this Dashboard you can create your Build Jobs, Views and automation scripts using Groovy, which I may discuss in coming blogs.
I sincerely hope you enjoyed reading this article. Docker offers a ton of other valuable features like these, which I intend to discuss in my upcoming blogs. Consider becoming a follower if this sounds like something you’d be interested in.