Create a Jenkins job for installing docker and launch the container automatically

Create a Jenkins job for installing docker and launch the container automatically

**Introduction:
**Setting up a robust Continuous Integration and Continuous Deployment (CI/CD) pipeline using Jenkins with GitHub integration is crucial for achieving efficient and automated software development workflows. In this step-by-step guide, we’ll walk through the process of creating a Jenkins CI/CD pipeline integrated with GitHub, enabling you to automate builds, tests, and deployments for your projects. Follow along to streamline your development process and enhance collaboration within your development team.

Requirements:

  • AWS account.

  • Jenkins and Docker are to be installed on the AWS EC2 Instance

  • GitHub repo (code)

Step 1: Setup AWS EC2 Instance

We will first create an AWS Instance (Ubuntu) free-tier eligible using the AWS console.

Steps To launch the EC2 instance:

  1. Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.

  2. Choose Launch Instance.

3. Once the Launch an instance window opens, provide the name of your EC2 Instance.

4. Choose the (AMI)

5. Choose an Instance Type. Select t2.micro for our use case which is also free-tier eligible.

6. Select an already existing key pair or create a new key pair. In my case, I will select an existing key pair.

7. Edit the Network Settings, Create a new Security Group, and select the default VPC with Auto-assign public IP in enable mode. Name your security group and allow ssh traffic, HTTPS, and HTTP from anywhere (later on we can modify the rules).

8. Leave the rest of the options as default and click on the Launch instance button.

9. click on Connect to instance.

10. Now connect to instance wizard will open, go to SSH client tab and copy the provided chmod and SSH command.

11. Start Jenkins:

$ sudo systemctl enable jenkins
          $ sudo systemctl start jenkins
          $ sudo systemctl status jenkins

Now also do that first ….

Git Installation: Ensure that Git is installed on the machine where Jenkins is running, and the path to the Git executable is correctly configured in the Jenkins global settings.

#install git 
yum install git -y

Privilege escalation:

vi /etc/sudoers

This is Github Repo:

Login Jenkins:

ipaddress of your instance :8080

go to manage jenkins and**search github api plugins

  1. On Jenkins Dashboard, Click on New Item to create your first job or item.

Enter the name of your first item and select Freestyle Project and click on Ok.

after click ok

Now we will go to build section scroll down and select execution sell

Now we will write the code

sudo yum install docker -y 
sudo systemctl start docker
sudo docker run -dit --name raghav -p 8000:8000 vimal13/apache-webserver-php

and save it.

after all steps we will click on build option

After clicking on Build Now we see in the output console that the build has been finished successfully

Thank you for investing your time in reading this blog. Your support and interest inspire me to continue sharing knowledge and insights.

Remember, learning is an ongoing journey, and I’m here to help and support you along the way. Feel free to reach out, ask questions, or share your thoughts. Together, we can accomplish incredible things!