Docker provides excellent universal application packages. All operating systems offer official Docker images. For example, the image jenkins/jenkins is available through 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.
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.
Installing Jenkins from a Docker image is a simple process. Here are the fundamental steps to get started:
docker pull jenkins/jenkins:lts
FROM jenkins/jenkins:lts-jdk11
After this, we can do other installations. This command downloads the latest version of Jenkins.
docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
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.
Running Jenkins from a Docker image is a quick and easy way to start Jenkins in a self-contained and pre-configured environment.