Run Jenkins in Docker
Jenkins is supported to run in Docker, especially for testing purposes, docker is very convenient and environment-independent.
Create a Docker Volume for Jenkins
Run the Jenkins Docker
Bash
docker run --name jenkins --detach \
--volume jenkins-data:/var/jenkins_home \
-p 8080:8080 \
--restart=on-failure \
jenkins/jenkins:jdk21
Configure User
Then, we need to get the temporary admin password from the docker logs.
Bash
$ docker logs jenkins
*************************************************************
*************************************************************
*************************************************************
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
9af6eb9845e746f08078109ed03f1df4
This may also be found at: /var/jenkins_home/secrets/initialAdminPassword
*************************************************************
*************************************************************
Then open http://ip:8080
,
- input the temporary admin password
- then, the Jenkins will ask to install some plugins
- then, set username and password for the Jenkins instance
Upgrade Jenkins Running In Docker
When there is a new version of Jenkins docker released, we can easily upgrade it with the following steps,
-
Pull the latest Jenkins Docker Image
Run
docker pull jenkins/jenkins:jdk21
-
Remove the existing container
Run
docker rm -f jenkins
-
Rerun the Jenkins Docker Container From the New Image
Run the command in above section
Run the Jenkins Docker
, the new container will be running in new version.