How to install and work with the Jenkins Docker image

Docker provides excellent universal application packages. All operating systems offer official Docker images. For example, the image jenkins/jenkins is available through Jenkins.

What is Jenkins?

Jenkins is an open-source automation server for software project continuous integration (CI) and continuous delivery (CD). It includes a web interface for configuring and managing automation jobs, which can be triggered by changes in source code repositories or on a schedule.

Prerequisites

Docker must be installed to run a Docker image. Jenkins only provides Docker images that are based on Linux. We'll download and install Docker on our local machine if we haven't already.

Downloading and running Jenkins

Installing Jenkins from a Docker image is a simple process. Here are the fundamental steps to get started:

  • Using Docker pull: In our terminal or command prompt, we’ll run the following command to retrieve the Jenkins image from the Docker Hub registry:
    docker pull jenkins/jenkins:lts
    
  • Using Docker image: If we want to do other installations using Jenkins, then we’ll use the following command:
    FROM jenkins/jenkins:lts-jdk11
    

After this, we can do other installations. This command downloads the latest version of Jenkins.

  • Launch container: Once the image has been downloaded, we’ll use the following command to launch a container from it:
    docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
    
  • Accessing Jenkins: We can access the Jenkins web interface once the container runs by opening a web browser and going to http://localhost:8080. The Jenkins setup wizard will appear, guiding us through the initial configuration of our Jenkins server.
  • Next, we’ll follow the setup wizard’s instructions to create an admin user and install any required plugins.
  • We can automate our build, test, and deployment processes after configuring Jenkins.

Note: Because Jenkins stores its configuration and job data in the container’s file system, deleting the container will result in losing our data. To save our data, use the -v option in the Docker run command to mount a volume from our host machine to the container. Consider the following example:

docker run -p 8080:8080 -p 50000:50000 -v /path/on/host:/var/jenkins_home jenkins/jenkins:lts

This command mounts the directory /path/on/host on our host machine to the container’s /var/jenkins home directory, where Jenkins stores its data. This allows us to keep our data even if the container is deleted.

Conclusion

Running Jenkins from a Docker image is a quick and easy way to start Jenkins in a self-contained and pre-configured environment.

Copyright ©2024 Educative, Inc. All rights reserved