0% found this document useful (0 votes)
22 views12 pages

CI Handson With Docker

Uploaded by

SAJJAN SHAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views12 pages

CI Handson With Docker

Uploaded by

SAJJAN SHAH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

CI SESSION3 HANDSON WITH DOCKER

https://github.com/DEVOPS-WITH-WEB-DEV/jenkins-share
d-library1.git

https://github.com/DEVOPS-WITH-WEB-DEV/spring-cloud-k
ubernetes.git

NOTE – Once you copy the Jenkinsfile in STEP 10 please


comment the stages after Docker cleanup.

PREREQUISITES

1)AWS LOGIN
2)DOCKER HUB LOGIN
3)GITHUB HUB LOGIN
**** COST WILL OCCUR IN AWS ACCOUNT BELOW 100
Rupees***

STEP 1 – CREATE A T2.MEDIUM UBUNTU EC2


INSTANCE IN AWS IN US-WEST-1 REGION
● 8GB is sufficient

STEP 2 - Install JDK on AWS EC2 Instance

sudo apt-get update


sudo apt install openjdk-11-jre-headless -y
java –version

STEP3 - Install and Setup Jenkins

https://github.com/praveen1994dec/tools_installatio
n_scripts/blob/main/jenkins.sh

Step 4: Setup Jenkins

- Now go to AWS dashboard -> EC2 ->


Instances(running)and click on Jenkins-EC2
- Copy Public IPv4 address.
- Change the SG to open for Jenkins.
- Alright now we know the public IP address of the
EC2 machine, so now we can access Jenkins from
the browser using the public IP address followed
by port 8080.

- Copy the below key and paste it on JENKINS

- After completing the installation of the suggested


plugin you need to set the First Admin User for
Jenkins.

STEP 5 - Update visudo and assign administration


privileges to jenkins user

- Open the file /etc/sudoers in vi mode


sudo vi /etc/sudoers

- Add the following line at the end of the file

jenkins ALL=(ALL) NOPASSWD: ALL

-After adding the line save and quit the file.Now we


can use Jenkins as root user and for that run the
following command
:wq!

su – jenkins

STEP6 - Install Docker with user Jenkins

https://github.com/praveen1994dec/tools_installatio
n_scripts/blob/main/docker.sh

STEP 7 - Add Docker and GitHub Credentials on


Jenkins

- Setup Docker Hub Secret Text in Jenkins


You can set the docker credentials by going into -
Goto -> Jenkins -> Manage Jenkins -> Manage
Credentials -> Stored scoped to jenkins -> global ->
Add Credentials [ GIVE YOUR DOCKER HUB
CREDENTIALS ]
STEP 8 – ADD MAVEN IN GLOBAL TOOL
CONFIGURATION

STEP 9 – ADD JENKINS SHARED LIBRARY

Go to Manage Jenkins -> Configure System -> Global


Pipeline Libraries ->

Give Library name – jenkins-shared-library


Default Version - main

Project Repository - https://github.com/DEVOPS-


WITH-WEB-DEV/jenkins-shared-library1.git

STEP 10 - Build, deploy and test CI/CD pipeline


Create new Pipeline: Go to Jenkins Dashboard or
Jenkins home page click on New Item

Pipeline Name: Now enter Jenkins pipeline name and


select Pipeline

Add pipeline script:

Click on Configure -> Select Pipeline ->

https://github.com/praveen1994dec/spring-cloud-ku
bernetes/blob/main/kubernetes-configmap-reload/Je
nkinsfile -> Copy that Jenkinsfile -> Paste it in
Pipeline Script in Jenkins
Step 11 - SELECT BUILD WITH PARAMETERS [ IF FAILS
AGAIN START THE PIPELINE ]
Action – create
ImageName - kubernetes-configmap-reload
ImageTag – v1
AppName - kubernetes-configmap-reload
Docker_repo – Give your Docker Hub account ID

DOCKER LOGIN

STEP 12 – ADD WEBHOOK

IN GITHUB PROJECT - > SETTINGS -> WEBHOOK -> URL


–> http://<ec2_ip>:8080/github-webhook/ -> ONLY
FOR PUSH EVENTS

IN JENKINS -> GO TO GENERAL TAB -> BUILD TRIGGERS


-> ADD GITHUB WEB HOOK TRIGGER
Step 13 – Add the trigger in Jenkins

Step 14 – DOCKER HANDSON WORK

Before you start the hands-on comment the docker


clean up stage so that images are not getting deleted.

Login to the EC2 instance and execute below


commands:

Command 1 – List docker images

docker images

Command 2 – Convert the image to container


docker run -d -p 8081:8080
praveensingam1994/kubernetes-configmap-reload:lat
est

Command2.1 – Go inside the container and check the


JAR

docker exec -it <containerID> /bin/sh


ls -lrta

Command3 – Create a network for docker

docker network create batch3

Command 4 – List the networks

docker network ls
Command 5 – Connect the container with the created
network

docker network connect batch3 46fe13f0a263


docker network connect <Network Name>
<ContainerID>

Command 6 – Inspect the network


docker inspect batch3
docker inspect <network name>

Command7 – Hit in browser the below endpoint by


replacing the IP

http://<EC2IP>:8081/home/data

Command8 – Delete the Container

docker stop <containerID>


docker rm <containerID>

Command9 – Remove the network

Step 15 – Delete the EC2 instance

You might also like