To install Jenkins in a Docker container and You can download the Docker Community Edition from the official Docker website.
https://hub.docker.com/r/jenkins/jenkins
Pull the Jenkins Docker image from Docker Hub using the following given command.
$docker pull jenkins/jenkins
Run the docker images using the following command.
docker run -d –name jenkins -p 8080:8080 -v /path/to/jenkins-data:/var/jenkins_home jenkins
Note:
-d runs the container in detached mode (i.e.used run the container in the background)
–name jenkins sets the name of the container to “jenkins”. -p 8080:8080 maps port 8080 on the host machine to port 8080 in the container, so that you can access the Jenkins web interface from outside the container
-v /path/to/jenkins-data:/var/jenkins_home mounts a volume at /path/to/jenkins-data on the host machine to /var/jenkins_home in the container. This is where Jenkins will store its data, such as configurations, plugins, and build artifacts.
You can access the Jenkins web interface by navigating to http://localhost:8080 in your web browser.
Steps to create persistence volume. (persist Jenkins data even after the container is stopped or recreated, you can create a Docker volume using the following command)
$docker volume create jenkins-data
Then, you can modify the docker run command to use the volume instead of a host directory
$docker run -d –name jenkins -p 8080:8080 -v Jenkins-data:/var/jenkins_home Jenkins
To access the Jenkins console output, you can use the docker logs command
$docker logs -f jenkins
Steps to stop the Jenkins
$docker stop Jenkins