Share on Social Media

In this article, you will learn how to run Jenkins in Docker. #centlinux #docker #jenkins

What is Jenkins? :

Jenkins is a free and open-source automation server. Jenkins helps in automation of software development processes related to building, testing and deploying, thus it facilitates continuous integration and continuous delivery.

Jenkins is written in Java and it is distributed under MIT License.

Jenkins is server based system that runs in a Java servlet container such as Apache Tomcat.

Environment Specification:

We are using a preconfigured Docker Host with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 4 GB
  • Storage – 60 GB
  • Operating System – CentOS 8.1
  • Hostname –
  • IP Address – /24

Pull Jenkins image from Docker Hub:

Connect to Docker Host ( as root user by using a SSH tool.

Use the docker command to search for the available jenkins images.

# docker search jenkins --filter is-official=true
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
INDEX       NAME                        DESCRIPTION                     STARS   OFFICIAL   AUTOMATED   Official Jenkins Docker image   4800    [OK]

There is only one official Jenkins docker image available, that has been deprecated in favor of jenkins/jenkins:lts image.

jenkins/jenkins:lts image is maintained by the Jenkins community and it is the most suitable and up-to-date docker image.

Pull the Jenkins docker image by using the following command.

# docker pull jenkins/jenkins:lts
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.
Trying to pull
  name unknown: Repo not found
Trying to pull
  invalid status code from registry 503 (Service Unavailable)
Trying to pull
  manifest unknown: manifest unknown
Trying to pull
Getting image source signatures
Copying blob d108b8c498aa done
Copying blob 1bfe918b8aa5 done
Copying blob 9d647f502a07 done
Copying blob cc4fe40d0e61 done
Copying blob 3192219afd04 done
Copying blob 17c160265e75 done
Copying blob dafa1a7c0751 done
Copying blob b2d02276dac1 done
Copying blob 2c0d0c8c3efd done
Copying blob 96361a673333 done
Copying blob 81c6f1bc405d done
Copying blob 0a46f33b1b25 done
Copying blob 30eaf72640cc done
Copying blob f4b226e89c35 done
Copying blob bb775209c68a done
Copying blob 27df1ec63d52 done
Copying blob 229f7473962e done
Copying blob afd6ff4cc063 done
Copying blob c69f789a4a12 done
Copying config 6328c71fe3 done
Writing manifest to image destination
Storing signatures

Run Jenkins in Docker Container:

Now, we have the required Jenkins docker image. So we can create and run a Jenkins docker container by using the following command.

# docker run -p 8080:8080 
> -p 50000:50000 
> --name=jenkins-master 
> -v jenkins_home:/var/jenkins_home 
> -d --env JAVA_OPTS="-Xmx8192m" 
> --env JENKINS_OPTS="--handlerCountMax=300" 
> jenkins/jenkins:lts
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.

Complete Documentation of the Jenkins Docker image is available at Git Hub. Here, we are only using few necessary parameters.

  • -p 8080:8080 -> Maps the Jenkins Web UI port of Docker container to Docker host.
  • -p 50000:50000 -> Maps the Build Slaves port of Docker container to Docker host.
  • –name=jenkins-master -> Name of the Jenkins docker container
  • -v jenkins_home:/var/jenkins_home -> Bind mount for storing Jenkins container data and configurations.
  • -d –env JAVA_OPTS=”-Xmx8192m” -> Set a JVM memory parameter
  • –env JENKINS_OPTS=”–handlerCountMax=300″ -> Set the JENKINS_OPTS environment variable
  • jenkins/jenkins:lts -> the image used to create Jenkins docker container

Allow the required service ports in Docker host firewall.

# firewall-cmd --permanent --add-port=8080/tcp
# firewall-cmd --permanent --add-port=50000/tcp
# firewall-cmd --reload

Access Jenkins Web UI:

Browse URL by using a Google Chrome browser.

Jenkins Web Interface
Unlock Jenkins

Since, we are accessing the Jenkins web interface for the first time, therefore, we need the admin password to sign-in into the Jenkins web interface.

The path to password file has been provided by the Jenkins web interface. Therefore, we can use Docker cp command to copy this file to Docker host machine.

# docker cp jenkins-master:/var/jenkins_home/secrets/initialAdminPassword .
Emulate Docker CLI using podman. Create /etc/containers/nodocker to quiet msg.

Display the contents of this file to obtain the admin password.

# cat initialAdminPassword

Login to Jenkins web interface by using this password.

Jenkins Dashboard

We have successfully run Jenkins in docker container. If you want to learn more about Jenkins usage then you should read Continuous Delivery with Docker and Jenkins: Create secure applications by building complete CI/CD pipelines, 2nd Edition (PAID LINK) by Packt Publishing or you can enroll in Jenkins for Beginners course at Udemy.

Leave a Reply

Your email address will not be published. Required fields are marked *