Jenkins Tutorials: Install Jenkins as Docker Container

In the Previous Post we Learned How to install Jenkins as Servlet on Tomcat server.

In this post we will try even simple and easy way to run Jenkins on your machine using docker.

Like all major servers Jenkins also comes as a light weight container and is being maintained by community aggressively.

Pre-requisites :
1. Basic docker understanding.
2. Docker should be up and running on the host machine.
If you feel you need refresher for any of the above – try searching it on devopsschool.com – we have plenty of content available 🙂

Let’s start, first check docker daemon is running on the machine where you want to install Jenkins as container.

For me, I’m going to do it on my mac machine locally – steps would be pretty much similar if we want to do it on cloud machine as well.

Run,

docker version

It should some like below on screen :

docker version

Run docker command :

docker run -p 8080:8080 -d jenkins

Let me explain what we did above , we are asking docker to run Jenkins container on port 8080 for the localhost host machine which will be routing traffic to port 8080 to the Jenkins container and -d tag tells to run this container in detached mode.

If we don’t have the Jenkins container image locally, docker will go and download it from the docker hub registry. You will see something like this below as out put.

running Jenkins container

Now goto http://localhost:8080

Jenkins home page

Now a big question how to find out admin password ??? as the password would be in container and not in local host machine, we should get it from there.

Run below command :

docker exec <containerID> cat /var/jenkins_home/secrets/initialAdminPassword

This will print out the admin password on screen, something like this:

Note, as container ID gets generated on the run time. It would be different for you and me.

Lets copy this password and enter it on the jenkins dashboard :

If you are seeing dashboard like above – congratulations you have successfully installed Jenkins as docker container pat your back and start using it.

More on Jenkins in the upcoming lectures. If you like this article feel free to check other articles by me.

Gaurav Bajpai