Hi Readers, Continuous Integration and Continuous Deployment is the core part of DevOps practices. Jenkins is one of the CI/CD tools. In this blog, we will see how we can set up Jenkins in a Docker container.
- Jenkins is an open source, self contained automation tool written in Java.
- It streamlines continuous integration and continuous deployment task in software development life cycle process.
- Jenkins supports all operating systems.
- It is a server based application and it requires a web server, Apache Tomcat to run.
Multiple ways to install Jenkins
Jenkins installation is possible in many ways,
- Native system packages,
- Run standalone by any machine with a Java Runtime Environment (JRE) installed,
In this blog we will see how we can install Jenkins using Docker.
- Docker is an open platform for developing, shipping and running applications.
- It isolates our application from our infrastructure and this isolation enables us to deliver software quickly without any outside intervention. These isolated environment are containers.
- Docker methodologies for shipping, testing and deploying code quickly significantly reduces the delay time between writing and deploying code to production.
Jenkins Installation on Docker container
Get Jenkins image from docker hub
Firstly we need to get the docker image of Jenkins from the docker hub, Docker hub is basically a cloud-based image repository provided by Docker itself. For quick reference see this.
Once you have the image run the below command,
- docker run
- It runs the Jenkins image. It initially searches for the image locally and if not found it downloads it from the docker hub.
- -p 8080:8080
- -p tells the port where Jenkins will run.
- Jenkins application inside container will run it on port 808, because Jenkins runs on Tomcat which by default uses this port.
- -p 50000:50000
- 50000:50000 is the port where Jenkins master and slave communicates. This helps to bind slaves(if any).
- -v jenkins_home:/var/jenkins_home
- This will bind volumes and persist data of Jenkins.
- We want to bind volume because when we remove container, restart and recreate it, we want our data to be persisted.
- We are here specifying the image name with latest tag.
Unlock Jenkins using initial admin password
Once the above command is executed, this means you now have Jenkins image locally and you have Jenkins is running inside a container.
Secondly, we need to Unlock Jenkins, and for that, you need an initial admin password which is there in the terminal window.
Install initial suggested plugins
Thirdly we need to install all the suggested plugins to get started.Plugins are used to enhance the functionality of Jenkins in order to achieve the various use cases.
However we can install more plugins from the plugins manager later on, but for now we can go ahead with suggested plugins only. This will take few minutes to finish.
Manage initial admin account
Once we have all the plugins installed we are prompt to create our first admin user. These credentials are required to login to your Jenkins dashboard every time you hit http://localhost:8080/
In conclusion, we have now successfully set up Jenkins inside a container. In the next blogs, we will explore more on the Jenkins dashboard and try to create some projects and pipelines to understand more.
Thank you for following this blog till the end. If you found this blog helpful do share this blog with your colleagues. In case of any feedback, suggestion or question reach out to me at firstname.lastname@example.org.