Skip to content

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

Bash
$ sudo docker volume create jenkins-data
jenkins-data

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

https://www.jenkins.io/doc/book/installing/docker/

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,

  1. Pull the latest Jenkins Docker Image

    Run docker pull jenkins/jenkins:jdk21

  2. Remove the existing container

    Run docker rm -f jenkins

  3. 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.