How to Install Jenkins,Git,Docker on Amazon EC2 Instance
Published: 2022-11-13 01:49:41

In this part, I will show how to install and launch Jenkins,Git,Docker on a AWS EC2 instance.

Let's get start with Jenkins

## Installing Jenkins

- Create Ubuntu 18.04 EC2 Instance. Once you logged in to your AWS account and accessed your Ubuntu Server 18.04 LTS instance you can follow the below steps to install Jenkins.

- Update Ubuntu Server Before installing Jenkins you have to update software packages on Ubuntu server for that use below commands.

`sudo apt-get update -y`

- Add Repository Key You have to add Jenkins repository into Ubuntu server.

`wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/of9mxrsff4vpq8ktcdu8.png)

- Add Package Repository

`sudo sh -c 'echo deb http://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iy8zaz6tyefzff9lnn7o.png)

- Now, to update the server

`sudo apt update`

- Install Jenkins Dependencies We first have to install java

`sudo apt install default-jre -y`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e4ec2lanmah7ua5r22if.png)

`sudo apt install jenkins -y`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uhwu62fzvxx4yl89o4ia.png)

- And Jenkins installation completed you have to start Jenkins service

`sudo systemctl start jenkins
sudo systemctl status jenkins`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rhf82edak12oi9ipzw9e.png)

- Allow Jenkins Port On Ubuntu Firewall By default Ubuntu server has firewall installed and we have to allow Jenkins port 8080 from firewall so that we can access Jenkins.

`sudo ufw allow 8080`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ab3okkgt6rssxhpbg3oo.png)

- If the Ubuntu machine firewall is not enabled, you can use the commands below to check it.

`sudo ufw status`

- If your Ubuntu firewall is inactive use

`sudo ufw allow OpenSSH 
sudo ufw enable
sudo ufw status`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nrgxghpexzkoochmvrs8.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/f999559crrl87vwrw3sj.png)

- Setting Up Your Jenkins Now to access Jenkins from web browser you must also allow Jenkins port 8080 in AWS security group and after that you will be able to access Jenkins. So go to your AWS account-Security group and add port 8080.

- As a last part, pen web browser and type your AWS Ec2 Ubuntu instance public IP address with 8080 port.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q3ot61jumfgrq432xiab.png)

- As per the instructions in the screenshot above, you need to get the default admin password from the given path, so on your Ubuntu machine you would issue the following command to get it.

`sudo cat /var/lib/jenkins/secrets/initialAdminPassword`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9s5kd929ub5u7qhobgzk.png)


- You will get the following output and this is the default admin password to login to Jenkins copy this and use it in web browser for Jenkins login.

- When you login to Jenkins with default admin password, it will present two options and this is recommended plugins and choose plugins to install. We recommend clicking on the suggested plugins and jenkins will take care of the plugin installations.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cmnivk95wly9k67fzoie.png)

- The plugins will take some time to install and once all plugins are installed Jenkins will ask you to create your Admin user account. Next, fill in your desired admin user details and set Jenkins admin credentials.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/avx6rcx7ufsqzfxg87fq.png)

- Click Save and Finish after setting your Jenkins access url and other information. Finally you will get a confirmation page and it will be "Jenkins Ready".


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h8wzt81gpp7mm8y13t1a.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tuz1x5onql2rb3f78zh4.png)

## Installing Git

- Update Ubuntu Server Before installing Git you have to update software packages on Ubuntu server for that use below commands.

`sudo apt-get update -y`

- Install Jenkins Dependencies

`sudo apt install git -y
git --version`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ywkeo2jxurg8nxpm8g3z.png)


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ggmlvjb5wp42632mtjp8.png)

### What's Docker?

Docker is an open platform for developers and sysadmins to build, ship, and run distributed applications.

## Installing Docker

Running Docker on AWS provides administrators and developers a highly reliable, cost-effective way to build, ship, and run distributed applications. Docker can be installed on many different operating systems, including Linux distributions like Ubuntu and even Mac OSX and Windows.

`sudo apt-get update`

`sudo apt install docker.io`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/arefvxlv0pyks80iq0gq.png)


`service docker.io start
service docker.io status`

- Basic Commands for Docker


`sudo docker info`


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yz796z6njiuemy35qff0.png)


`sudo docker images
sudo docker ps`



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p86118ct75eanjxy8es4.png)


`Run Docker Image: By default, docker pulls the images from a Docker registry called Docker Hub managed by Docker company. To confirm whether you can download the images from Docker Hub:`


`sudo docker run hello-world`



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v87niirivmb0fl40i46i.png)