Implementing CI/CD Pipelines with Docker and Jenkins
Last Updated :
27 Aug, 2024
Modern software development has CI and CD pipelines as its core practices, fostering the delivery of code faster, more reliably, and with fewer errors. CI/CD pipelines generally automate the process of building, testing, and deployment to ease the development process, so that the lifecycle becomes smooth through code changes and their integration and deployment.
This in combination of Docker and Jenkins will prove a lot more powerful in automating CI/CD. Docker ensures that the application runs in the same working environment, and Jenkins automates every phase of the pipeline—starting with fetching the most recent code from a repository to deploying the application into a production environment.
The article shows how CI/CD pipelines are set up using Docker with Jenkins, how the pipeline is used, and elaborated examples. By the end of this tutorial, you should have a clear understanding of how to set up and manage CI/CD pipelines that leverage the power of Docker containers and Jenkins automation.
Primary Terminologies
- Continuous Integration: A practice of automatically integrating the changed code committed by developers to the shared repository after each commit, followed by automated testing to detect issues early
- Continuous Deployment: A practice of automatically deploying every change that passes through the CI phase into production so that the latest code is always made available to its users.
- Docker: An open-source platform utilizing containerization to package and deploy an application properly in a consistent way in any environment.
- Jenkins: An open-source automation server that runs the continuous integration and deployment initiative by automating the process of building, testing, and deploying applications.
- Pipeline: An automated suite in the sequence for building, testing, and deployment in applications, mostly defined as Jenkinsfile.
Step-by-Step Process for Implementing CI/CD Pipelines with Docker and Jenkins
Step 1: Install Docker
Install docker by using the following command
sudo yum -y install docker
Start and enable docker
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
Step 2: Install Jenkins
Now install jenkins by using following commands
sudo wget -O /etc/yum.repos.d/jenkins.repo \
https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key
sudo yum upgrade
sudo yum -y install java-17*
sudo yum -y install jenkins
Now start and enable jenkins by using following commands
sudo systemctl start jenkins
sudo systemctl enable jenkins
sudo systemctl status jenkins
- Now navigate to ec2 dashboard and copy public ip of instance and browse it along with port 8080 because jenkins default port number is 8080
- Copy and paste administration password and unlock jenkins
Install Required Plugins
Now Navigate to Manage Jenkins -> Manage Plugins.
Install the following plugins:
Step 3: Create a Jenkins Pipeline
Create a New Pipeline Job:
- In Jenkins, click New Item.
- Enter a name for your job, select Pipeline, and click OK
Define Your Pipeline in a Jenkinsfile:
- Give project description
- Now go to pipeline section add pipeline script
pipeline {
agent any
stages {
stage('Pull Nginx Image') {
steps {
script {
// Pull the Nginx Docker image
dockerImage = docker.image('nginx:latest')
dockerImage.pull()
}
}
}
stage('Test') {
steps {
script {
// Run tests inside the Nginx container (you may need to adjust this based on your test needs)
dockerImage.inside {
sh 'echo Running tests on Nginx container...'
// Example: Check Nginx version
sh 'nginx -v'
}
}
}
}
stage('Deploy') {
steps {
script {
// Example of deployment step (optional)
// Here, we would normally push to a registry, but Nginx is usually pulled directly from Docker Hub.
echo 'Deployment step for Nginx container (usually unnecessary as Nginx is directly pulled)'
}
}
}
}
}
Step 5: Build Pipeline
Now Build pipeline
Here we can see the output of the pipeline
Below figure shows that pipeline view of the job
Conclusion
The Docker and Jenkins CI/CD pipelines are a great way to automate and ease the development process. In the present scenario, a bundle of such integrated tools can ensure shorter development cycles, improve the reliability of tests, and smoothen deployment without differences or inconsistencies across any environment.
The containerization technology developed by Docker ensures that applications run consistently from development through production. Jenkins, on the other hand, provides an automation framework to build, test, and deploy those applications. These join forces in enabling one continuous integration and deployment process to reduce market time with better software quality.
Any team of developers that aims at embracing DevOps really needs to understand the key terminologies and steps that are in place to have these pipelines set up. With the correct configuration, your software is always in a state where it can be deployed; as a consequence, you enable fast iterations and the continuous delivery of value to your users.
To put it in other words, mastering CI/CD with Docker and Jenkins enables teams to automate workflows, prevent errors, and deliver high-quality software faster. This makes CI/CD a cornerstone of effective software development in today's fast-paced world
Similar Reads
Implementing Canary Releases with Docker
In the world of today in software development, deployment strategies play a very important role in ensuring application stability while rolling out new features. One such strategy for effective changes is the canary release. Docker, being flexible and scalable technology, fits perfectly within the i
6 min read
How to Make a CI-CD Pipeline in Jenkins?
Pre-requisites: Jenkins DevOps professionals mostly work with pipelines because pipelines can automate the processes like building, testing, and deploying the application. Doing manually by UI takes lots of time and effort which will affect productivity. With the help of Continuous Integration / Con
5 min read
Java Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development wo
5 min read
Python Application Deployment In Kubernetes With Jenkins CI/CD Pipeline
In modern software development, deploying applications to Kubernetes clusters has become a common practice due to their scalability and reliability. Automating this deployment process using continuous integration and continuous deployment (CI/CD) pipelines with Jenkins streamlines the development wo
6 min read
Spring Boot Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how we can actually deploy Spring boot applications on Kubernetes with the help of Jenkins CI/CD.
14 min read
Node.Js Application Deployment in Kubernetes with Jenkins CI/CD Pipeline
As we know in the modern world we use Continuous Integration and Continuous Deployment for fast and and efficient delivery of our application to the market. Here in this Article, we are deep-diving into how Actually we can deploy Nodejs applications on Kubernetes with the help of Jenkins CI/CD. Prim
9 min read
Using Ansible in Jenkins Pipelines
In the fast-paced software development scene, DevOps practices have become significant for associations expecting to convey excellent software quickly and dependably. DevOps underscores collaborations, automation, and continuous integration and delivery (CI/CD) to smooth out the software development
6 min read
Understanding Jenkins CI/CD Pipeline And Its Stages
Jenkins is an open-source automation server that enables developers to reliably build, test, and deploy applications. It supports continuous integration and continuous delivery (CI/CD) workflows that allow teams to frequently deliver high-quality software. Jenkins is extremely popular, with over 100
15 min read
Introduction To Jenkins Pipeline As Code (Jenkinsfile)
Jenkins is an automating web server that build using java programming language. It come with support large number of plugins that made it as power CI/CD tool supporting to integration most of the softwares. In this article we will guide you through how to setup Jenkins Pipeline as Code from the scra
5 min read
Git and DevOps: Integrating Version Control with CI/CD Pipelines
It is quite surprising how many development teams find themselves with problems such as version control for code, consistency concerns, and the problem of releasing updates. When these challenges are not accompanied by proper version control mechanisms or a CI/CD system integration, they result in i
11 min read