First we try to understand the what is jenkins and why jenkins is used in devops.
🚀 What is Jenkins?
Jenkins is an open-source automation server used primarily for Continuous Integration (CI) and Continuous Delivery (CD) in software development.
It helps automate the process of:

Building code

Testing applications

Deploying software

Monitoring pipelines

Jenkins is one of the most popular tools in the DevOps toolchain.
🛠️ Why is Jenkins Used in DevOps?
In DevOps, the goal is to:

Develop faster

Test more often

Deliver software reliably and continuously

Jenkins makes this possible by automating everything.
what is use of docker agent in Jenkins?
Old Jenkin Architecture:
Image description
if you refer the old jenkins architecture in organizationi, we created EC2 instance jenkin master but there are lots of devlops,devopments teams so jenkins gets lots of load so to offload this things so you should always use jenkin master only for the scheduling purposes. so in organization people create jenkin master and jenkin worker nodes, so different application run on different worker node. in past this architecture is well and good but advancement of microservices, we have lots of application os with this type of approach its difficult to build as well as some worker node sitting idle. so to solve this problems the new architecture came in the picture.
New Jenkin Architecture:

Image description

in latest approach, we are using Jenkins with docker as agent. so in latest approach we are trying to run jenkin pipeline on docker containers. as we know docker container is light in weight instead of virtual machines

Now you understood what is jenkin as well as docker as agent so we will try to configure the docker agent in Jenkins.
first login to EC2 instance using external terminal using below command:

Image description
Jenkins is java based application so first install the java as Pre-Requisites:

Java (JDK)

Run the below commands to install Java and Jenkins

Install Java

sudo apt update
sudo apt install openjdk-17-jre

Verify Java is Installed

java -version

Now, you can proceed with installing Jenkins
curl -fsSL https://pkg.jenkins.io/debian/jenkins.io-2023.key | sudo tee \
/usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \
https://pkg.jenkins.io/debian binary/ | sudo tee \
/etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt-get update
sudo apt-get install jenkins

*Note: * By default, Jenkins will not be accessible to the external world due to the inbound traffic restriction by AWS. Open port 8080 in the inbound traffic rules as show below.

  1. EC2 > Instances > Click on
  2. In the bottom tabs -> Click on Security
  3. Security groups
  4. Add inbound traffic rules as shown in the image (you can just allow TCP 8080 as well, in my case, I allowed All traffic).

Image description
Login to Jenkins using the below URL:
http://:8080 [You can get the ec2-instance-public-ip-address from your AWS EC2 console page]

Note: If you are not interested in allowing All Traffic to your EC2 instance 1. Delete the inbound traffic rule for your instance 2. Edit the inbound traffic rule to only allow custom TCP port 8080

After you login to Jenkins, - Run the command to copy the Jenkins Admin Password - sudo cat /var/lib/jenkins/secrets/initialAdminPassword - Enter the Administrator password

Image description
Click on Install suggested plugins

Image description
Wait for the Jenkins to Install suggested plugins

Image description

Create First Admin User or Skip the step [If you want to use this Jenkins instance for future use-cases as well, better to create admin user]

Image description

Jenkins Installation is Successful. You can now starting using the Jenkins
Jenkins Installation is Successful. You can now starting using the Jenkins

Image description

Install the Docker Pipeline plugin in Jenkins:
Log in to Jenkins.
Go to Manage Jenkins > Manage Plugins.
In the Available tab, search for "Docker Pipeline".
Select the plugin and click the Install button.
Restart Jenkins after the plugin is installed.

Image description

Wait for the Jenkins to be restarted.

Docker Slave Configuration

Run the below command to Install Docker
sudo apt update
sudo apt install docker.io

Grant Jenkins user and Ubuntu user permission to docker deamon.
sudo su -
usermod -aG docker jenkins
usermod -aG docker ubuntu
systemctl restart docker

Once you are done with the above steps, it is better to restart Jenkins.
http://:8080/restart
The docker agent configuration is now successful.