In this video, learn how to run Jenkins from a Docker container on your local workstation.
- [Instructor] One of the fastest and easiest ways to get up and running with Jenkins on your local workstation is to use Docker. Docker is a tool that bundles applications into portable pieces of software called containers. The really great thing about using an application in a container is that all the application's dependencies are included. Other than the Docker program itself, there's nothing else to install before you run the application. For example, you can run Jenkins in a Docker container without having Java installed on your system.
The Java that Jenkins needs to run is packaged along with it. Other than getting Jenkins up and running, I won't go into too much more detail on using Docker, but if you want to learn more, there are great courses here on Lynda that you can turn to for more information. So let's get started with running Jenkins on Docker. If you're following along, be sure to reference the exercise files for this lesson for the commands I enter during the installation. First, you need to have Docker installed on your system. You can find installer for Mac, Windows, and Linux at docker.com/community-edition.
Look for your operating system and follow the links to download the installer. On the specific page for your OS, you'll also find instructions for how to complete the installation. Once you have Docker installed and running, open a terminal window and type docker --version. This'll just make sure that everything is set up appropriately. Now type docker images. This command lists the images that are available on your local system. If you haven't downloaded any containers yet, you should see an empty list.
Now type docker pull jenkins/jenkins:lts. This will download the latest Jenkins image. While we're waiting for this download to complete, I can share that running Jenkins on Docker is also a great way to get a fresh up-to-date installation of Jenkins that you can use for testing and experimenting without much commitment. Say, for example, you want to test a plugin or a technique that you'd like to use on your main Jenkins installation.
You can run those tests using a Docker image and not have to worry about disrupting your main Jenkins installation. Okay, now that the Docker pool is complete, type docker images again. You should see the Jenkins image listed now. Now, run the following command. Docker run --detach --publish 8080:8080, - -volume jenkins_home:/var/jenkins_home, - -name jenkins, and then jenkins/jenkins:lts.
Again, I won't go into all the details of this Docker command, but the result of running it will have Jenkins running on your local system and accessible via port 8080 on localhost. Though running Jenkins through Docker is pretty easy, I mean, after all, you've only typed a few commands so far, there is one trick. Getting the initial admin password. New Jenkins installations are locked down by default, and you need to get that password to log in. But if Jenkins isn't running directly on your system, how do you get the password? I found the easiest way is to run another Docker command that connects to the running container and prints the password for you.
It looks like this. Docker exec jenkins cat /var/jenkins_home/secrets/initial, and then Admin, with a capital A, and then Password, with a capital P. After running this command, you should see the initial admin password printed to your terminal.
Copy it and then open localhost:8080 in your browser. In the browser, enter the admin password and click continue. Then click install suggested plugins. This will complete the Jenkins by installing the plugins that are most commonly used by Jenkins. Depending on the speed of your laptop and your internet connection, this may take several minutes to complete.
Once the plugins are installed, you'll be prompted to create your first admin user. At this point, you should create your account, with a username of your choice and a password that's easy to remember but hard for others to guess. In this case, I'll just be using demo. Also, enter a name and an email address. For now, the email address doesn't have to be a valid one, but it does have to have a valid email format, with a name, an at sign, and a domain. Note that you do have the option to skip creating a user by clicking continue as admin.
This is fine, but just know that if you log out and log in, you'll need to enter the initial admin password, the same one that was used during the install. Once the form is filled in, click save and finish, and then click start using Jenkins. You're now ready to start using Jenkins through this Docker install. For the rest of this course, I'll be running Jenkins from a Docker container. If you're looking for more information on Docker specifically, I encourage you to take a look at some of our other courses, which go into far more depth.
First, learn how to set up Jenkins on Mac, Windows, Linux, or inside a Docker container, and find out how Jenkins plugins are used to extend its functionality. Next, configure your first job step by step, leading up to the requisite "Hello, World" output, and learn to make your jobs more useful and portable with parameters. Then explore job scheduling, and Jenkins's convenient aliases for running jobs at regular intervals. The course wraps up with tips for organizing jobs in folders and views and a brief look into pipelines as code-which enable you to execute a series of jobs in stages.
By the end of the training, you should be able to install Jenkins locally or on a virtual machine, create a Jenkins jobs that can be triggered manually or on a schedule, and install and configure plugins to extend the Jenkins framework.
- Installing Jenkins
- Using plugins
- Creating and configuring a job
- Running and monitoring jobs
- Managing artifacts
- Working with parameters
- Scheduling jobs
- Organizing jobs with views and folders
- Defining stages with pipelines