To run Jenkins in a Docker container, you will need to have Docker installed on your machine. Then follow these steps:
Pull the Jenkins image from Docker Hub:
docker pull jenkins/jenkins:latest
Create a volume for Jenkins to store its data:
docker volume create jenkins-data
Create a directory to store the Jenkins configuration:
mkdir jenkins_home
cd jenkins_home
Run the Jenkins container, mapping the host machine’s port 8080 to the container’s port 8080, and setting the name of the container to “jenkins”:
docker run --name jenkins -p 8080:8080 -v $(pwd):/var/jenkins_home jenkins/jenkins:latest
Wait for the container to Once the Jenkins container is running, you can access the Jenkins web interface by going to http://localhost:8080 in your web browser.
Read, then copy the password.
cat secrets/initialAdminPassword
To stop the Jenkins container, use the following command:
docker stop jenkins
To start the Jenkins container again, use the following command:
docker start jenkins
To remove the Jenkins container and all its data, use the following command:
docker rm -v jenkins
Note that this will delete all data stored in the jenkins-data volume, so make sure you have a backup if you need to preserve this data.