DevOps: How to Use Docker in Your Jenkins Pipeline Job | Docker Plugin

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
welcome well using Docker with Jenkins offers several advantages for our continuous integration and continuous deployments Dockers allows for containerization which means that applications and its dependencies can be bundled together in a lightweight isolated environment so that's about the docker stuff so in this session let's see how to use Dockers with our Jenkins pipeline jobs note that you will need to install Docker in the host where you will be running this job in my case I have installed Dockers in the same Jenkins server VM you can actually refer my other video Docker installation in Ubuntu VM I'm Kumar and welcome to my channel on Tech and tutorials so we have our Docker installed in our Jenkins server machine so now for using Docker we need to install some plugins in our Jenkins server so let's go to manage Jenkins and go to the manage plugins here in the available section we will search for Docker so we need to install two plugins for us to work smoothly with Dockers so this is the first one Docker and then the other one is the docker plugin okay so we can go ahead and install without restart so let's see if it works sometimes we would need to restart our Jenkins server for using our Dockers so let us try to install without restart okay so looks like it is installed so let us go back to our top page and go ahead with creating a new job to test our Docker plugins so new and we'll put check Docker plugin okay so we're going to create a pipeline job for this and click OK and let us go down and we will create a pipeline script for this we are not going to use any GitHub or any code base we are just going to check some Docker commands from our pipeline script so before checking that let me actually show you one thing so the pipeline syntax and Global variables now you will see the docker in the global variable which has some commands which you can use with Dockers in the pipeline script okay this is coming from that Docker pipeline plugin so these are all the options with Docker which you can do and for this session we will see one command for Docker which is going to be the image and then we are going to run the run one Docker image from our pipeline script okay so this starts to show Once you install the plugins okay Docker and the docker pipeline plugin let us go inside here into our pipeline script and try simple script let's put the hello world and we'll try to put one stage here run Docker okay and let me actually remove this one Echo and we'll try to run one Docker image here let's try to run one httpd image okay so this is the docker hub for httpd image we will use one small small image for this and the Alpine ones are the Alpine ones are usually the smallest one and let us use this Alpine one okay so let us come back to our our Jenkins pipeline job and let us Define one image first here so we'll use the httpd 2.4 Alpine this is probably this one of the smallest images which will download and run our httpd Docker image so the command which we need to write is Docker dot image and then the image name which we have to put here so our image name is already defined so let us put our dollar and the curly braces and the our variable sorry and our wave close our curly braces and we have to change this to double quotes Okay and then we have to provide the Run option dot run if you come here if you come here and you see here run image dot run and then it takes arguments so these are the arguments which we'll put minus p and all the other options so we'll use only a couple of arguments here so one is the minus P argument for the port which we'll use and D minus D detached mode and minus P okay for the ports so this httpd usually runs in the 80 port for our application HTTP application and the external Port also will put it as 80 okay so it's going to run on my Jenkins server 192.168.1.1.50 okay so that completes our pipeline script and let us save this save and then let us try to run this till now and in the meantime let us go to our server okay and let us see the docker image so now there is only one hello word and looks like our job failed so let us go and check what is the problem okay image Docker dot expected is symbol okay so okay so I I forgot to tell you here what we need to do is we need to provide this whole thing inside a script block okay otherwise this is not going to work so we need to provide this inside a script block okay so let me close the curly braces and let us put the indentation proper and let us save this now and save and do a build now let us see looks like it started to run and it's trying to pull down the image HTTP image and pulling from library this is a Public Image so we don't need an username and password okay so download a newer image for blah blah and then it's looks like it ran so let us go to our server and check the images okay and Docker PS should show our image which is this HTTP 2.4 and looks like it is running so what we need to do is we need to check in the browser okay we copy this a new tab and then put the port 80 and you should see the httpd is working now okay so yep everything seems to be fine so so that completes this session we have seen about the two plugins that we need to install for user working with Docker in Jenkins and then we have seen one small pipeline job using the Docker plugin so thank you so much and see you in the next session
Info
Channel: Kumar'S
Views: 2,782
Rating: undefined out of 5
Keywords: jenkins, docker, devops, ci/cd, docker in jenkins, docker plugin jenkins, jenkins pipeline with docker
Id: H9ZHnJb3Zw8
Channel Id: undefined
Length: 6min 10sec (370 seconds)
Published: Fri Jun 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.