Create Jenkins Pipeline to Build Docker Image for Python App & Push Docker Image into Docker Hub

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
we are going to create a jenkins pipeline for automating docker image creation we are going to use one of the application which is hosted in bitbucket it's a python based application which is completely dock right okay and we are going to use jenkins which already has docker installed and we are going to uh create a docker image and then upload the docker image into docker hub okay so this is what we are going to do and then once we upload the docker image into docker hub we are going to run the container as well inside the jenkins okay this is a very simple lab that's what we are going to do i already have jenkins upon running which also has docker installed okay and i also have my docker hub okay and this is where we are going to host our docker images okay and this is my bid bucket right this is our python based application right if you see here we have completely dockerized that if you look at the docker file as you can see here we are installing uh you know python and the necessary uh modules in order to run the application and then finally in i'm copying the source code and then you know copying the index.html as well exposing the port number uh for in 5000 and then you know we are going to run the application okay so this is the docker file okay and then if you look at my source code this is the python script right it's a very simple python script and then if you look at my html file which is the one you know when you run the container this is what it is going to show uh in the container right so it's a very simple python based application which is completely dockerize that this is what we are going to automate using jenkins so if you look at the pre-request we all have this isn't it we all have this okay and we must open port 8096 because we are going to run the application right i mean we are going to run the docker container we are going to expose on port a8096 and we don't need 8140 so that's the port number 8096 okay let me save it so all our prerequisites are already you know so we are meeting all the prerequisites okay awesome so let's get started so right now we need to create a credential for docker hub okay so let me go to jenkins go to manage jenkins and go to manage credential and we need to create a credential for docker hub why because look at this diagram we are going to create a pipeline okay that pipeline is going to build the docker image as well as it would it would also upload the docker image into docker hub as well right so we need to set up a credential for docker hub okay so let's do that click on jenkins and then global credential add credential so we are going to set up a user credential i mean you know what the username and password for docker hub so let me go ahead and do that okay so that's my credential okay i'm going to use the same for here as well okay so our credentials are set up and then the next step is to actually create the pipeline right awesome so let's go to jenkins create a job okay so i'm gonna say my docker pipeline job click on pipeline say okay all right so if you go to the build trigger yeah you can invoke however you want let's try to go with pole acm it doesn't matter i'm going to use okay i'm going to trigger once in every two minutes okay and then go to pipeline so this is for go to pipeline this is what we want to get started right so pipeline i'm going to say agent okay and we're gonna say stages and stage let's start with checkout right so that's the code okay and we're going to say steps so this is where we are going to write code for checkout all right awesome so let's start doing it let's go to pipeline syntax check out let's try to generate the code for checking out and this is the public repository so you don't have to put in the password create the script and then go ahead and then put that over here so that is our first stage right so let's quickly make sure this is good let me go ahead and run bill now okay so everything is good let me go back and let's start writing the next stage right so the next stage is we want to build docker image right so i'm going to say docker i'm going to say build docker image open braces and then steps okay and then we are going to do this way right so all you have to do is you don't need that script okay so we need to declare this variable docker image i would be declaring that under environment section okay okay so let's build the docker image okay there is some error we need to declare the registry let's go ahead and declare the registry here the registry is nothing but you know this particular entry right how do you want to talk to your docker registry right so the way should be is it should be your username and then your image name right okay so i want to give that image name okay i think now we can run this okay i think i made a typo here so let's go ahead and then run this awesome you see here the darker image has been built okay so so far so good and then let's move forward to the next stage our next stage is you know we want to once we build the docker image obviously right you know we want to upload into a docker hub okay so let's go ahead and then generate the code for uploading into docker hub so i'm going to say uploading docker or i'm going to say uploading image okay steps and we also need to have a script block as well right all right perfect and then the way we are going to upload into docker images we need to have the registry credential right so we need to have a credential so let me copy this this is the variable we are going to use right so what is our our variable name i think docker hub underscore id right so that's what we had under credential section okay docker hub id and we can verify that let's let's go there jenkins manage jenkins manage credential you see here docker hub id docker hub underscore id so that's what i'm also using that right so perfect right and then we have to write in the script block how you are going to upload the docker image okay so all you have to do is just mention this command perfect you see here so this is going to use the registry credential right what we have here and then this is going to push the docker image into docker hub okay that error is gone let's go ahead and bill now all right fantastic you see here docker image has been built and then it has been uploaded into docker hub and of course we can also see here as well
Info
Channel: DevOps Coach
Views: 39,705
Rating: undefined out of 5
Keywords: Jenkins Pipeline Docker Builds, Jenkins Pipeline, Create Docker image
Id: UTziA84ynvo
Channel Id: undefined
Length: 10min 43sec (643 seconds)
Published: Fri Sep 25 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.