Hello and welcome to this session on Jenkins
on Docker in this session We are going to go very basic step by step and we will see
how can we create a Jenkins server on a Docker container and we will see how to start Jenkins
on Docker container We will see how can we start and stop the Jenkins Container We will
also see how can we set Jenkins home or the home directory of Jenkins on docker volume,
or the host machines physical location So this is going to be easy and interesting So
let's get started and let me open my terminal now in case you are following this session
on Windows You can open your Windows command prompt or your power shell and case you are
watching this on Linux You can go to your Linux command line I am recording this on
a Mac operating system So I am going on Terminal and I will also split my screen So that you
can see the notes as well as the terminal window Okay So the very first step is we have
to get the Jenkins image from Docker So I am going to my browser and I will go to Docker
hub And here I will go to explore repositories and here I will search for Jenkins so you
can see I have got this very first option Jenkins I will go to the details And here
you can see the docker pull command is Docker pull Jenkins and this command will pull the
jenkines image onto our local system So I will say Docker pull Jenkins So this is using
the default latest tag, and it will start pulling the Jenkins image So now it is pulling
all the required libraries from Docker Hub. So you can see this is the very first command
this one that we are running now So now do docker pull is completed Let me clear the
terminal and if I go to Docker images you can see we have our Jenkins image created
and this is the image ID Okay, so we can also run Docker images and minus Q flag to just
get the image ID and all these commands we have learnt in the earlier session So now
we have just caught the image We do not have the container as of now, even if we say Docker
PS or Docker PS-A to list all the containers you can see there are no containers running
as of now So to create the container and to run the container Let us go back to our Docker
Hub and here if you go a little down you will find this command This is for running the
docker container So let us also understand this command here We are seeing Docker run
and -b command is to expose the port 8080 on the host system Mm, which corresponds to
8080 port for the docker server and similarly We are exporting Port 50,000, which is for
Jenkins API, and the image name is Jenkins now, if you run this command I can just copy
and run this command here This will start our Jenkins container start our Jenkins server
on a Docker container and you will be able to access Jenkins by localhost:8080 on your
system However with this command the data or the Jenkins home directory where all our
plugins all our jobs and all the information that we do on Jenkins is stored will be coupled
with the container and once you stop the container or delete the container all the data will
also be deleted with the container and we do not want that We want that We have a persistent
storage for our Jenkins home directory So for that what you can do is here is another
command which says you can actually use the minus V flag here and then give our local
location for your home Jenkins home which will correspond to where Jenkins home Okay
So let us try this one out and what I will do is I'll just copy this command and I will
paste it here on my terminal and here what I'm going to do is we are seeing Docker run
and let me also give a name to this container and we can say --name and I will say this
is my Jenkins one So I am giving a name which is optional step And then we are saying - be
to expose port 8080 of the container to port 8080 of the host machine and Port 50,000 of
the container or the server to Ports 50,000 on our host machine and then - And here I
can give some physical location on my system so I can say here I want to use users Raghav
desktop and I want to create a folder called Jenkins home here, which will correspond to
the Jenkins server where Jenkins home directory and this is the image Okay, so I will start
this now And let me also show you how it will create a folder so it should create a folder
here on my desktop So I am starting this and you can see a Jenkins home folder is now created
and this actually writing down all the Jenkins home elements or the data inside this folder
And you can see all this data is coming here So this is going to be very useful when you
work on actual enterprise-level projects with Docker and Jenkins So always do this step
and you can also actually create volumes which I will show you in the next step So let us
process complete and we have got this admin password that I will copy for reference Now
you can see the Jenkins is fully up and running so we can go to our browser and go to localhost
8080 And you can see the Jenkins starting page here I will give the initial admin password
So this initial admin password you can get from the locks here. This is the password or in case you have you
do not find it here You will always find in the Jenkins home They will be a Secrets folder
and then here will be initial admin password so you can find it here as well and you have
to give this here and continue And now because we are starting our Jenkins for the first
time here it is asking us to install some suggested plugins or to select plugins to
install you can click on install suggested plugins, but for now to make the process faster,I
will click on select plugins and I'm actually going to click on none so that this process
does not take a lot of time and I will just go to install and it is asking me to create
an admin user I will just continue as admin you can create some user if you want I will
continue Is admin and start using Jenkins Now here we have got our to our Jenkins dashboard
The very first thing I will do is I will go to my user here at the top Right and I will
go to configure so that I can set some password here I will just set some password that I
can remember easily here and apply and Save and now I will go to my Jenkins and go to
here new item And create a job So let me say this is job test one a freestyle job and say
okay. And you see I am not getting a lot of options
here because I have skipped all the plugins So in your case, you might get some more options,
but that is fine for now I'm just creating a shell command in the build step and apply
and Save. So the reason I'm creating a job here is I
just want to show what is the advantage of mounting or having a physical location of
the Jenkins home directory So you see I have created a test job here by the name job _test1
And now what I'm going to do is on my terminal, let me again split my screen
So you can see the Jenkins server is running so I will open a new tab of the terminal or
you can open a new command prompt and here I just want to check the running container
So I will say Docker PS and you can see our Jenkins is running and my Jenkins is the name
that we have given to this container Right? So what I'm going to do is I'm going to stop
this container so I will say Docker stop now I can give the container ID here, which is
this one or I can also give the name that I gave to my container So this is I am saying
Docker stop my Jenkins And now if I go to the terminal which was running you can see
this is shutting down Winstone So now it has come out of Jenkins server And if I see there
is no container running, but if I go to Docker PS-A I can still see my container is there,
but it is not running So to start the container I can say Docker start and the container ID
or the container name but what I'm going to do is I am going to remove this container
Okay So if I go to Docker PS-A there is no container And now what I'm going to do is
I am going to create a container again. So what I will do is I will create a container
again and this time I am going to give it a different name So I will say this is my
Jenkins 2 and the port I can keep it as it is or I can change the port number as well
So I want to start this on 9090 and this is okay And now you see what I am doing is I
am setting up the same Jenkins home directory that I used for the earlier container And
mapping it to the Jenkins home of the server for Jenkins and I will run this So the basic
thing that I am trying to show you here is by using a physical location You can actually
share your Jenkins jobs and plugins and all the data between containers So I have already
stopped and removed the earlier container and this is a new Jenkins container I am starting
and let this server get started successfully and then I will show you the jenkins dashboard
So you can see Jenkins is fully up and running And now if I go to localhost 8080 anyways,
will be down but now we can go to Local Host 9090 So I will go to Local Host:9090 and you
can see our Jenkins is up and it did not actually go to the very first page that comes normally
with a new installation of Jenkins It directly took us to the login page and I'm actually
using the credentials that I created on my earlier instance of Jenkins and I will try
to log in And let us see if it allows us to login And you can see we have logged in successfully
and also you can see this is the job that we created earlier which is available here
as well And the reason this is because we actually created a Jenkins home directory
and we are using the same Jenkins home for this container as well Now I could have also
started this new Jenkins container while the earlier one was already running So even that
I could have done but I wanted to show you that even if you exit and remove the container
you still have the data You can process the data by using this physical location So this
will be very handy when you want to use multiple containers or you want to share your data
with between multiple containers and you should always do this when you are working with Enterprise
projects Now, the other thing I wanted to show you is how you can set volumes So what
you can do is instead of setting up this physical location. You can also say if I go to Docker volume,
And I'll go to Docker volume create my Jenkins and I said Docker volume LS so you can say
my Jenkins volume is created and do not worry I am going to explain in detail about volumes
in the next session, but for now just see what I am doing I have create just created
a volume in Docker And now what I'm going to do is I will use the same command to start
a Jenkins container So I will copy this command here and I am going to use the same command
However, instead of giving a physical location I'm going to give the name of the volume that
I just created So I will say minus V flag and the name of my volume was my Jenkins and
of course you can go and see the volume For example, you can say Docker volume LS to list
the volume and then you can see Docker volume inspect and the volume name. So it gives us the details about the volume
and the mount Point Mount point is where it is available So the difference here is this
volume, although it's available on the host machine, but you won't be able to see it or
the functions will not be able to touch or change this volume So that is one of the advantage
and it becomes very easy to share between containers So here I am using this my volume
and I will do the same thing. I will just start my Jenkins container Okay,
so this is already in use So let me use a different name for the container I will say
this is my Jenkins3 So now this will start the Jenkins in the same way However, instead
of using a physical location it is using a Docker volume and this becomes very easy when
we want to share the volumes between multiple containers and also want to persist our data
So while this is getting started we just say Docker inspect and the name of the container,
which is my Jenkins3 and here if you go a little up, this is a Json file.If you go a
little up you will have the section for mounts and here you can see the volume The type is
volume name is my Jenkins and this is the source where it is located.Okay, so you can
also use volumes for Creating your data for your Jenkins server We will learn more about
pollens in the coming session, and this is how you start a Jenkins server on Docker container, and
this is all about that You should be knowing while running Jenkins on Docker I hope this
session was very useful for you I will meet you in the next episode Thank you for watching