Hi all, today we'll learn how to install Jenkins using Docker. Jenkins is an award-winning application that monitors executions of repeated jobs, such as building a software project or jobs run by cron. It builds/tests software projects continuously. In a nutshell, Jenkins provides an easy continuous integration system, making it easier for developers to integrate changes to the project, and making it easier for users to obtain a fresh build. The automated, continuous build increases the productivity. It helps in monitoring executions of externally-run jobs, such as cron jobs and procmail jobs, even those that are run on a remote machine. Jenkins keeps the outputs and makes it easy for you to notice when something is wrong.
Docker is an Open Source project that provides an open platform to pack, ship and run any application as a lightweight container. It has no boundaries of Language support, Frameworks or packaging system and can be run anywhere, anytime from a small home computer to high-end servers. It makes them great building blocks for deploying and scaling web apps, databases, and back-end services without depending on a particular stack or provider.
Here are the quick and easy steps below on how we can install Jenkins CI in a Docker Container so that it facilitates us with Docker environment.
1. Installing Docker
First of all, we need to make sure that we have Docker installed in our host Operating System. To install, we'll need to the run the following command in a shell or terminal.
Package docker is available in Ubuntu's repository so, we'll be using apt manager to install it in sudo or root mode.
# apt-get install docker
On CentOS 7
On CentOS 7 machine, we'll use yum manager to install docker as it is also available in CentOS's repository.
# yum install docker
2. Pulling Jenkins Image
After installing Docker in our host machine, we'll now go further towards installing Jenkins. We'll now pull Jenkins image from the Docker Registry Hub provided by zaiste. Before we pull the image using pull command, we'll need to protect our system as there is identified a malicious issue with pull command. To protect our system from this issue, we'll need to add 127.0.0.1 index.docker.io into /etc/hosts entry. We can do using our favorite text editor.
# nano /etc/hosts
Now, add the following lines into it.
Now, after we are protected from the malicious issue, we'll gonna start Docker Daemon. As we're running CentOS 7 in this tutorial, we'll use systemctl to start it.
# systemctl start docker
we'll now gonna pull our Jenkins image using the following command.
3. Running Jenkins Container
Next, we'll run a docker container using this image and map data directory from the container to the host. Here we map /var/lib/jenkins from the container to jenkins/ directory from the current path on the host. Jenkins port 8080 is also exposed to the host as 49001.
# docker run -d -p 49001:8080 -v $PWD/jenkins:/var/lib/jenkins -t jenkins-image
4. Web Interface
As we have successfully run Jenkins Container, we can browse Jenkins Web Interface using our Web Browser by pointing to http://ip-address:49001 or http://localhost:49001 according to the configuration. We have also added another article on how to setup Jenkin with Nginx with more details.
In the default configuration, Jenkins does not perform any security check which allows any person accessing the site can configure Jenkins and jobs, and perform builds. While this configuration is acceptable during initial evaluation of the software, Jenkins should be configured to authenticate users and enforce access control in most other situations, especially when exposed to the Internet.
Now, we'll go for some security measure, we'll add username and password. We'll go to Manage Jenkins > Configure Global Security and select the "Enable Security"check box. For basic username/password authentication, I would recommend selecting "Jenkins Own User Database" for the security realm and then we'll select "Logged in Users can do anything". Now, to add a new username and password, goto Manage Jenkins > Manage Users>Create User. Then, we'll add details for our new users.
We have successfully installed Jenkins with Docker. Jenkins is an awesome tool for monitoring automation builds. It can be used for the production of large scaled projects to small projects as it helps to increases the productivity. And Docker adds this tool a great platform for easy deploy and use of it. If you have any questions, suggestions, feedback please write them in the comment box below so that we can improve and update our contents. Thank you! Enjoy :-)