Jenkins job for installing docker and launch the container automatically with aws ec2 instance

Jenkins job for installing docker and launch the container automatically with aws ec2 instance

Step 1: Login into root user using sudo su

Step 2: Install java using yum install java -y

Step 3: Run the command on linux to configure yum and downloading a Jenkins repository configuration file (jenkins.repo ) from the specified URL and saves it to the directory on a Red Hat-based system.

sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo

Step 4: Run this command

sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io-2023.key

This key is used to verify the integrity of the Jenkins packages you download.

Step 5: Install jenkins using yum install jenkins

Step 6: Now start jenkins using

systemctl start jenkins systemctl status jenkins

Step 7: Give permission to jenkins.

vi /etc/sudoers

jenkins ALL=(ALL) NOPASSWD: ALL

every work in ec2 has done now sign in to jenkins using ip adress:8080

Step 8: Click on create item give the item name and choose freestyle.

Step 9: Click on build steps and choos execute shell after that write this code

sudo dnf install docker -y sudo systemctl enable --now docker sudo docker pull centos:latest sudo docker images sudo docker run -dit --name run_docker centos:latest sudo docker ps

Click on build now

your jenkins job for installing docker and launch the container automatically with aws ec2 instance.