How to Run Jenkins on Docker

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
in this video we're going to talk about how to run jenkins on docker [Music] you may be used to installing jenkins by using just the war file or maybe using the package that is available for your operating system you can also run jenkins and docker which means you don't have to install any bits directly on your operating system except for docker running jenkins on docker is the perfect way to simplify the installation as well as the ongoing maintenance of your jenkins controller here's today's starting point i have docker on an instance that's it we're going to walk our way all the way through this installation so the first question you may ask yourself is what version of jenkins do i need to pick now in this video i'm going to be picking a little bit older version so we can go through an upgrade so you can see how that step works so we're starting out at docker hub and if we look for jenkins jenkins that will land you on this page let's click over to tags and from here based on the current date that i'm recording the most recent lts is 2.303.2 so we're going to start with 2303.1 so i'm going to go to filter tags and i'm going to enter 2.303.1 and we can see here that i have numerous versions available to me now what i can see here is i have architectures available for both linux amd64 which is what i'm using today and also linux arm 64. if we scroll down a little bit further we can see that some images specifically this centos 7 based image is only available for linux amd so you're going to need to understand your underlying architecture in my case it's a centos 7.9 amd64 based box to figure out exactly which tag that you're going to want to run now another way that you can do this if you want to just search for lts you can do that and with lts we're going to see the latest which in this case is 2303.2 and for this top one we can see that it's available for linux amd64 linux arm64 as well as linux s390x if we keep going down through here we can see that a lot of these have multiples and then we get less until finally it's this singles again you need to understand what version of os and what architecture that os is running on so that you can determine which image is available for you to use so let's go ahead and get our shell up which is where i'm at right here i'm going to paste in docker run command and all the commands that we're going to be running today are going to be over in a gist the link to that gist is down in the description and we're just saying docker run rm so when the container stops it will remove the container i'm giving it a name of jenkins i am passing in ports 8080 and 50 000. now today we're only going to be using 8080 and then i am specifying the image tag that i'm wanting to pull in use in this case it's 2 303.1-jdk8 now i'm picking the jdk8 version of this image so that i can show you something with jdk 11 towards the end of this video so let's go ahead and run this so it's unable to find the image that's fine so it's going to download it start it up and then we're going to go through and set up our controller this will take just a few moments as it goes through extracts and starts up the controller okay so what we can do here just to speed things along a little bit let's copy this initial password we'll go back over to our browser here i'm going to go to the controller i'm going to paste in this password once it allows me to should be there momentarily here we go we'll unlock it and just to speed things along we're going to skip installing plugins today so i'm going to say none install just create a user here real quick because we're not going to be running any jobs in this video i just want to show you how to do things differently with docker to run your jenkins controller and click save and finished now we're going to start using jenkins so here is our jenkins controller so i could create a new item i guess i sort of lied didn't i i meant to say that we're not going to be running any jobs but i am going to create a job so i'm going to say test job test job freestyle click ok i'm not going to do anything other than just save it and we can see here on the dashboard i've got a test job now what's going to happen when i stop this container let's go back over to our shell we can see that it's running i'm not running it in the background just so you can see what's happening so when i stop this container i'm gonna do a control c and it stops it so right now if i take a look at docker ps there's nothing running if i take a look at docker psa there's nothing there either because we use the dash dash rm argument to automatically remove the container when it shuts down so if i was to start this back up again let's do that what's going to happen what we're going to see here is that we get prompted to install jenkins again and why is that the reason why is that we did not give docker a volume to attach to this container so once this renders up what we will see here is we're unlocking jenkins if i was to unlock jenkins again just to prove it out i'm going to say select plugins to install none and say admin admin admin admin and what we're going to see here is our test job that we created doesn't exist because there was no volume to persist the state across restarts so let's go back over to our shell we're going to stop this and now what we're going to do once i clear this let's paste this in and take a look at what's different everything is exactly the same except for the volume and what we're doing is we're going to be creating this volume jenkins underscore home which is sort of wrapped around and it's going to be mounted into slash var slash jenkins underscore home which is the expected jenkins home location within the container so let me back up here because i copy and pasted okay so what do we have docker run remove name ports volume and now the image so let's go ahead and run this and the reason why this is running faster we've already pulled the image down so we're not getting rid of the image each time we restart image still exists on the machine but what we haven't done is persist the volume until now so let's go ahead copy this password we'll refresh this page again it may still say we're starting up so we'll give it just a second to complete okay this time pass it in this time we're going to install suggested plugins so this will take just a moment and then let's set up our user saving continue save and finish start using jenkins then we have our controller let's go and create an item here we'll call it test job like what we did before i'll just select pipeline this time doesn't really matter and click on save so now we have saved a test job at the root of our jenkins controller so now let's go back over to our shell and stop the process so if we go back to the browser what we're going to see is it's just going to sit there and spin connection was reset that's fine let's go back over to our controller where it's living let's go ahead and start this again because we're passing in the volume it's going to mount in that volume as the container starts and once it completes the startup process then what we will see in our browser is we now have a login screen so let's log in as admin admin and we can see that our test job persisted the restart okay that's all well and good so now we have our volume but what happens when we're ready to upgrade to the next version of jenkins lts remember at this point we're running jenkins2303.1 down here in the bottom right hand corner so if we weren't using docker on our centos based box what we would do is we would say yum upgrade jenkins and everything would happen magically within that space but there's files that live in different parts of the file system whereas with docker we have our container image and the volume being managed by docker so it's a much cleaner implementation so let's go back in to our shell and let's do our upgrade well what does our upgrade look like so we did our shutdown and do a clear and the run line here is exactly the same as what we did before except for we bumped the 303.1 to 303.2 now let's watch what happens it couldn't find the image so it's got to go and download the image as it downloads the image and extracts it what's going to happen is the container is going to come up based on this new image 2303.2-jdk8 and then it's going to mount in that volume that we already had from the previous run and if everything goes well then what we're going to see is that our job still exists one other thing that you can see here is that we are upgrading jenkins which is passing by us here momentarily let me see if i can catch it again here we go this line right here upgrading jenkins the last running version was 2303.1 this jenkins is version 2303.2 okay that's good so it's doing what we expect and now the log is saying jenkins is fully up and running let's verify that we'll go back to firefox refresh this since it restarted we do have to log in again and we can see down here in the bottom right hand corner we have jenkins2303.2 now one more thing you may not realize is at the time of recording jenkins recommends that java 11 is the version of java to use to run the controller so how do we do that well let's go back to how we just started up our dot 2 image so let's go back to our shell let's go ahead and do a ctrl c do a clear and then let's change the tag from jdk8 to jdk 11. now it's important that we are staying on doubt two because our jenkins home currently is dot two so we're not changing anything specific about jenkins we are changing which version of the jdk is running jenkins inside of docker so again we'll hit enter not surprisingly this image does not exist locally so we need to go and download this image as it downloads and extracts once it completes it's going to bind in that volume that exists and then start up let's see what happens now as it's almost finished let's go back over to our browser we'll refresh here log in one more time and now we can see on the manage jenkins page we're no longer getting that notification about java 11 and in fact just to prove it out we'll look at system information and we can see the java version that we're currently running is 11 0 12. why should you run jenkins inside of docker in general containers are easier to manage and there's a good chance that the availability will be higher another couple of benefits is that it provides easier upgrades and better security if you must run jenkins outside of a containerized environment whether that's docker or kubernetes that's fine but the ongoing maintenance and management of your jenkins controller could be a lot more difficult as compared to running it within a container if you have any questions or comments you can reach out to us on twitter at cloudbeesdevs if this video was helpful to you give us a thumbs up and if you haven't subscribed to cloudbees tv yet why not take a moment click on that subscribe button and ring that bell and you'll be notified anytime there's new content available on cloudbeast tv thanks for watching and we will see you in the next video
Info
Channel: CloudBeesTV
Views: 612
Rating: undefined out of 5
Keywords: darin pope, jenkins, jenkins tutorial, jenkins docker
Id: QNZNfvrFBMo
Channel Id: undefined
Length: 13min 59sec (839 seconds)
Published: Tue Oct 19 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.