LAUNCH CONTAINER WITH DOCKERFILE CREATED IMAGE AND RUN WEB-PAGE ON IT USING JENKINS.

LAUNCH CONTAINER WITH DOCKERFILE CREATED IMAGE AND RUN WEB-PAGE ON IT USING JENKINS.

Hello Everyone!!Hope you all are safe and improving your technical skills.

So here I explain how I implemented my task 2 given by VIMAL DAGA Sir.

What do you understand by Automation? The creation and application of technology to monitor and control the production and delivery of products and services.”that means using automation you can launch your container and run different web-pages which is created and uploaded by user on Git-hub.We launch different container for different language interpreter and along with that we will monitor that container,all this will be done by Jenkins job and here automation come in play.

TOOLS TO BE REQUIRED: 1.GITHUB 2.JENKINS 3.REHL 8 4.DOKCER

TASK 2 DESCRIPTION: 1. Create container image that’s has Jenkins installed using Dockerfile.

2. When we launch this image, it should automatically starts Jenkins service in the container.

3. Create a job chain of Job1, Job2, Job3 and Job4 using build pipeline plugin in Jenkins

4. Job1 : Pull the GitHub repo automatically when developers push repository to Github.

5. Job2 : By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

6. Job3 : Test your app if it is working or not.

7. Job4 : if webpages areworking , then send confirmation email to developer.

8. Create One extra job Job5 for monitor : If container where app is running. fails due to any reason then this job should automatically start the container again.

!!!SO LET START OUR TASK 2!!!

STEP 1: Firstly you have to create a Dockerfile in which you have to install Jenkins and using that dockerfile you have to launch the Container.

So I firstly create a folder

#mkdir myjenkins (so here folder is created using myjenkins)

#cd myjenkins (to go inside the folder you use cd command which take you inside myjenkins folder)

#pwd (using pwd you can check the directory )

SERVICE WHICH YOU HAVE TO RUN:

#systemctl start docker (this will start the docker service)

Now the main step come you have to create docker file

#gedit Dockerfile (this is the command to create dockerfile)

DOCKERFILE

=>Now we have to build the image using dockerfile:

docker build -t task:v1 /root/myjenkins (build the image with name task:v1 )

BUILDING IMAGE USING DOCKERFILE
IMAGE CREATED

!!SO HERE YOU CAN SEE THAT IMAGE HAS BEEN BUILD SUCCESSFULLY!!

STEP 2:Launch the container using the image which you have been created using dockerfile i.e task:v1 is my image

#docker run -it --privileged -p 9999:8080 -v /:/host --name jenkins task:v1 (launching container with --name Jenkins on the port 9999 when you are running with IP of rehl 8 and port 8080 is when you are running the --name Jenkins container using container IP.

JENKINS CHROME IP - 192.168.43.225:9999

JENKINS CONTAINER IP - 172.17.0.2:8080 (when running on Firefox in rehl8)

LAUNCH CONTAINER

STEP 3: To go to the jenkins using IP and port

PUT PASSOWRD AND CONTINUE

AFTER THAT INSTALL ALL THE SUGGESTED PLUGINS

DOWNLOAD SUGGESTED PLUGIN

AFTER INSTALLING ALL THE PLUGINS JENKINS WILL START

JENKINS IS READY

Go to GitHub and choose your repository and open it

NOW GO ON SETTINGS=>WEBHOOKS

GITHUB REPOSITORY


WEBHOOK

PLAYURL - PUT YOUR JENKINS URL AFTER THAT PUT /github-webhook/ at last. CONTENT TYPE - application/json EVENTS -Let me select individual events MARK :Pushes and Pull request

Job1 : Pull the GitHub repo automatically when developers push repository to Git hub. So Firstly you have to integrate Jenkins with GitHub .

DESCRIPTION OF JOB 1
Copying all the files of github to the myjenkins folder

=>COPYING ALL THE FILES WHICH DEVELOPER HAS UPLOADED ON GIT HUB INTO MYJENKINS FOLDER.

No alt text provided for this image


COPYING IS SUCCESSFULLY DONE

?JOB 2:By looking at the code or program file, Jenkins should automatically start the respective language interpreter install image container to deploy code ( eg. If code is of PHP, then Jenkins should start the container that has PHP already installed ).

DESCRIPTION OF JOB 2
TRIGGERING JOB 2 AFTER JOB 1 IS BEEN SUCCESSFULLY EXECUTE

JOB 2:It basically check whether the file is having .html extension or .php extension after that it will launch the container accordingly .So here we have launch container for html as well as for php language interpreter.

--name myhtmlos is the name of container which is launching on the port -p 8082 MYHTMLOS IP -172.17.0.3:8082

--name myphpos is the name of container which is launching on the port -p 8082 MYPHPOS IP -172.17.0.4:8083

CODE TO LAUNCH DIFFERENT CONTAINER WITH DIFFERENT  LANGUAGE INTERPRETER

=>here chroot is used to replicate the directory of docker container to our BaseOS. In other words , Jenkins is working on a container so the GitHub files will be copied to folder /root/myjenkins in the docker container. But we have installed docker images in Base OS and we need to run the .html and .php files from it .

Hence using chroot we can replicate our /myjenkins from container to our BaseOS.

CONTAINER CREATED


=> IF EVERYTHING IS WORKING GOOD YOU CAN CHECK THE WEB PAGES WHICH HAS BEEN DEPLOYED

!!!SUCCESSFULLY RUNNING PHP WEBPAGE!!!
!!SUCCESSFULLY RUNNING HTML WEBPAGE!!

JOB3: Test your app if it is working or not.

SO HERE I DIVIDED INTO TWO PART ONE FOR PHP AND ANOTHER FOR OUTPUT OF JOB3 PHP WEBPAGE

IT IS WORKING GOOD

CODE TO CHECK THE STATUS OF HTML WEBPAGE

No alt text provided for this image

OUTPUT OF JOB 3 HTML CODE

Job3 : Test your app if it is working or not.

IT IS WORKING GOOD

JOB4 :IF WEB PAGES ARE WORKING GOOD THEN SEND CONFORMATION EMAIL TO DEVELOPER.SO HERE I USED EMAIL PLUGIN TO SEND THE MESSAGE TO THE DEVELOPER.

JOB 4 :DESCRIPTION
No alt text provided for this image
No alt text provided for this image
EMAIL SEND SUCCESSFULLY!!

JOB5 FOR MONITOR : IF CONTAINER WHERE APP IS RUNNING IS FAIL DUE TO ANY REASON THEN THIS JOB SHOULD AUTOMATICALLY START THE CONTAINER AGAIN.

That means job 5 will monitor your container and tell user if it app is working fine or not.

DESCRIPTION OF JOB 5
No alt text provided for this image
No alt text provided for this image

THIS CODE IS SHOWING US WHETHER OUR CONTAINER IS RUNNING FINE

BOTH THE APP IS RUNNING FINE

!!! SO HERE ALL THE JOB IS BEEN CREATED SUCCESSFULLY!!!

BUILD PIPELINE USING ALL THE JOB

PIPELINE BUILD

I HOPE THIS MIGHT HELP YOU.

THANK YOU!! FOR READING MY BLOG :)

I WOULD LIKE TO THANKS VIMAL SIR FOR GIVING US SUCH INTERESTING TASK.I FACED LOTS OF DIFFICULTY IN CREATING THIS TASK BUT STILL I AM HAPPY THAT I HAVE COMPLETED THIS TASK.HOPE YOU ALL ENJOY .

!!!STAY SAFE STAY HAPPY!!!

#righteducation #docker #jenkins #github #iiecrise










Priyanka Rathore

Senior Systems Engineer | .NET Full Stack Developer | .NET, .NET MVC, .NET Core, Angular 7+, Web API, RESTful APIs, Entity Framework, Microservices, SQL Server, No-SQL, C#, JavaScript, HTML/CSS, jQuery, Bootstrap.

4 年

Great!!

Ravi Malvia

Associate DevOps Engineer @Clouddrove Inc.

4 年

Well done??

MAYUKH B.

Master's in CyberSecurity at SUTD #Fuzzing #Vulnerability Research #dynamic testing #SIEM #PEN TEST

4 年

Quite good work !!..

要查看或添加评论,请登录

Sejal Rathore的更多文章

  • GOOGLE CLOUD PLATFORM

    GOOGLE CLOUD PLATFORM

    What is GCP cloud ? Google cloud platform(GCP) it is the public cloud invented b google.This cloud provide us different…

    6 条评论
  • WordPress launch on Aws using terraform

    WordPress launch on Aws using terraform

    Hello Everyone!! I am back with another project. Install software- 1.

    4 条评论
  • FLOWER AND FACE RECOGNITION USING VGG16

    FLOWER AND FACE RECOGNITION USING VGG16

    !!!HELLO EVERYONE!!! !!!HOPE YOU ALL ARE SAFE AND EMPOWERING YOUR TECHNICAL SKILLS!!! So today I am come with another…

    10 条评论

社区洞察

其他会员也浏览了