Docker Build & Publish Using Jenkins !

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] foreign so in today's video I'll be showing you how you can use Docker with Jenkins in this video what we'll be doing will be using a Java based spring boot project and we will build that project and using a Docker file we will create a Docker image of that project and then we will create a Docker using doc Docker image we will create a Docker container and then we will run the application and access the application from the browser okay so all those things you can just follow the video for that also make sure that you have installed a Java Maven and Docker on your Jenkins okay so with that being said let's get started okay so this is the Jenkins instance I have created on Ubuntu machine from AWS so as of now I have not done anything so let's just start by installing some plugins so for that we will click on manage Jenkins and then click on manage plugins and in available plugins what we will do we will install some plugins so first of all I will search for open jdk okay so I will install both of them and click on install without start restart and here you can see the list of plugins that have been installed and if you scroll down we can see the progress like when the plugins will be installed okay so you can see it says success now so we will scroll up go back to available plugins and search for docker because we are going to use docker so okay so first one third one and yeah okay maybe this one also okay okay so yeah this much is fine and we can click on install without restart again progress we can see in this section okay I guess this might take little bit of time because there are multiple plugins multiple dependent plugins that needs to be installed okay so let's wait for it to complete yeah this is almost done and after this is done what we will do we will configure Java and maven so now we will go back to manage Jenkins okay Maybe foreign Global tool configuration and here we will open jdk provide a name I will install open jdk8 and for the installer we will remove this commercial one from Oracle make sure that this option install automatically is checked on and expand this option add installer and select install from adoptium and here yeah we will let it be also like side by side what I will do I will add another open jdk which is of uh 11 open jdk 11 okay okay in the same process difference will be just we will select a different version of jdk select this setup install from adoptium and select open jtk 11.0.17 now we will scroll down to maven we will add one Maven so provide the name is 113 and this is the latest version so we will use this only and for Docker also will provide Docker name install automatically yeah Docker version also will be using lettuce so this all things have been configured now we will click on apply okay so now everything has been configured Java Maven Docker now we just need to create start creating these Jenkins jobs and then we can run them okay okay so before we start creating Jenkins jobs there is one more thing that we need to do okay so basically since we are going to run our Jenkins jobs using Jenkins user so we need to make sure that it has access to build and push images so for that we simply need to run this command which makes sure that Jenkins user is added in Docker group okay so we just need to do that and we will copy this and paste it on our Linux server okay so once this is done then we just need to restart our Jenkins so we will run the command as sudo system CTL restart Jenkins once you run this then you are good to go and then you can build and publish images using Jenkins user okay now coming back to dashboard this is Jenkins page and we will launch our first job so we'll click on create job and I'll provide the name as Docker Dash build Dash push okay and we will create a freestyle job for now so we'll select that and click on OK now and this option discard old builds I'll just keep as maximum maximum builds key to keep is to and select the jtk version as 8 because we are going to use a jdk 8 based project and for source code management I will select get and provide a URL for this specific project you can also use the same because it is open source I will paste the URL here and since it is open source so we do not need to provide credentials here okay so we will set the credentials to none scroll down Branch will name will be Master yeah and then scroll down to build steps now initially what we will do we will build the application to generate artifact for that we can select invert invoke top level 11 targets okay here select Maven version to Heaven 3 in goal I will set as install yeah so final step will be to Docker build and publish now here you need to provide a repository name so since I am going to use Docker Hub and this is uh like in Docker Hub it provides you to create one private repository so the repository name is this one I have just created it okay I will copy the repository name and paste it here for tag what we will do we will provide at a variable sort of thing because we want that the number build number will be used as tag so we'll provide this and provide the name as build underscore number okay and then scroll down to registry credentials so this is basically the credential for your Docker Hub registry okay so the credential that I used to log into this repository same credential I have added here and that is done and then we will click on apply and then we will build the application so we can see the progress here let me open the console output you can see it is downloading the ah dependencies and plugins for building the application so application has been built now it is building the docker file using building the docker image using Docker file and now it is pushing the docker image okay so let me quickly go here and here you can see only two images we are there as of now okay bus but once the job is Success then there will be extra image okay so let me run the command Docker images now you can see there is another image added here with tag 1 and latest same thing if you want to see we can go back to Docker Hub if I refresh this page yeah you can see two images have been pushed just now few seconds ago okay so this is good next what we will do is like create uh create a Jenkins pipeline job and then finally we will run the docker container to access the application in browser okay okay now we'll create a pipeline job so for that again we will click on new item provider name as pipeline Dash docker select the pipeline option click ok we will select discard old option in that maximum number of builds to keep two scroll down and yeah so let's take a sample pipeline hello world and let's change some things in it so first of all there will be three stages so we will copy this and paste it three times also side by side let me open this pipeline set text option because we'll be needing it so first of all we need to provide the uh like Java and Maven to be used in the whole pipeline so for that we'll be using this option tools in curly brackets and format will be first will be a tool type so jdk then in quotes name of the jdk tool pen jdk 8. next tool type is maven in quotes we'll be having maven 3. okay now the first stage will be copying the project source code creating a local copy so name will be a cm and then we will go to pipeline syntax and from here we will select the kit option inside kit we will paste the URL of our Repository Branch will be master and credentials since it is open source so no credential required click on General pipeline script copy this and we will paste it in our pipeline so let's paste it here okay so first is done next is we'll be building the application so Maven build and here simply we can write the command as sh double quotes and m v n clean install now last stage will be for Docker okay so here we will provide the name as Docker build and push yeah also since we need to run Docker command so what we need to do before anything create a script now we will paste our Docker command inside this script okay so again coming back to this pipeline syntax scroll down and select the option with Docker registry and here since residue URL we are not going to provide because we can let it be blank for public Docker Hub registry so in my case I'm using Docker up only so I will keep it as blank okay pastry credential I have already added in manage credential in Jenkins so in select one and Docker installation actually this is not required okay yeah see Docker installation even if you do not provide then then also it is fine so we'll copy this one paste it in our pipeline yeah make sure that we are pasting it inside the script okay now here we will provide the command command will be Parker build we will tag it with a certain name Docker build hyphen t and name we need to provide so for name what I will do I will just copy this repository name we will change the tag copy it paste it here in place of tag we can provide uh like tag one two three and second command will be Docker push okay yeah okay let's see what happens I will save this configuration in the job and click on build now and let's see in console output what happens it failed okay the spelling mistake I think we provided wrong okay so let me just copy this the jdk name we provided it wrong so let us just correct it so scroll down and paste it here yeah apply again trigger the job now the job has started and we can monitor what happens okay so it is running for the the building of application has been done a maven clean install that process got successful jar has been generated coming to this Docker command so it is it has logged in using the docker credentials okay okay so this got failed because we did not provide the path of the docker file okay and if I go back to here you can see Docker file is on root so what I will do I will click on configure and here we will just add a little thing white space and a dot dot means that Docker file is in current directory okay click on apply save and build now again you can see it is building it is in Docker stage now so okay image got built and it got tagged also but it failed in Docker push command okay we did not provide any argument till Docker push let us just correct it will just provide the name of the image in Docker push till the tag again click on apply and run one last time and let's see what happens okay yeah so since we have provided the docker image name now it is pushing Docker image got post and this job is Success now now to see the changes we can go back to our Docker Hub Repository refresh it one time and our image is here Docker tag one two three four opens you all if I go back to Linux run the command as current images yeah so both the images that we have created is here with tag one two three and one two four okay now what I will show you like how to run the application from Docker image okay foreign container out of this Docker image and then access the application on browser okay so image is already there what I will do we will run the command as Docker run iPhone P for Port will be 18 then 8080 and the name of the image so we will copy paste this colon type one to four now let's see what happens yeah so the application is starting inside the docker container from get started okay now what what I will do using the IP address of the machine let me paste it here column t sorry column 80 slash then we need to provide this in the URL and yeah so you can see the application is up and running now and we can access it and see the details on our browser so this is how like you can run an application from your Docker container same thing we can see here okay all the details about application it is running inside Tomcat on port 8080 and it has started okay so that's pretty much about today's video and I hope this video was interesting for you if so then thanks for watching
Info
Channel: DevOps Shack
Views: 36,309
Rating: undefined out of 5
Keywords: jenkins docker, jenkins docker image, jenkins docker build, jenkins pipeline docker, jenkins build docker image, install jenkins docker, jenkins and docker, docker build and push, docker build, docker build using dockerfile, dockerfile, build and push docker image, docker images, how to build docker image in jenkins, build docker image with jenkins, how to integrate docker with jenkins, video, tutorial, devops shack, free, devops, docker devops, docker, jenkins
Id: BePJ1bBWk3E
Channel Id: undefined
Length: 20min 0sec (1200 seconds)
Published: Thu Dec 29 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.