Site icon CentLinux

How to run Jenkins in Docker Container

Share on Social Media

Learn how to run Jenkins in Docker with this step-by-step guide. Discover how to set up, configure, and manage Jenkins within a Docker container for efficient and scalable continuous integration and delivery. #centlinux #docker #jenkins

What is Jenkins?

Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) in software development. It helps automate the parts of software development related to building, testing, and deploying, facilitating DevOps practices. Here are some key features and aspects of Jenkins:

Key Features of Jenkins

Use Cases for Jenkins

Conclusion

Jenkins is a robust and versatile automation server that plays a crucial role in modern software development practices. By automating the build, test, and deployment processes, Jenkins helps teams deliver high-quality software faster and more efficiently. Its extensive plugin ecosystem, ease of use, and strong community support make it a popular choice for implementing CI/CD pipelines.

Recommended Online Training: DevOps con Docker, Jenkins, Kubernetes, git, GitFlow CI y CD

Docker Host Specification

We are using a preconfigured Docker Host with following specifications.

Read Also: How to install JFrog Artifactory on CentOS 7

Pull Jenkins image from Docker Hub

Connect to Docker Host (docker-01.centlinux.com) 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
docker.io   docker.io/library/jenkins   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 registry.access.redhat.com/jenkins/jenkins...
  name unknown: Repo not found
Trying to pull registry.fedoraproject.org/jenkins/jenkins...
  invalid status code from registry 503 (Service Unavailable)
Trying to pull registry.centos.org/jenkins/jenkins...
  manifest unknown: manifest unknown
Trying to pull docker.io/jenkins/jenkins...
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
6328c71fe374c19ecc3df6b7ab5528ffaaca8e8fcdb000c8aa270b9368ccbb7f

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

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

Allow the required service ports in Docker host firewall.

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

Access Jenkins Web UI

Browse URL http://docker-01.centlinux.com:8080 by using a Google Chrome browser.

Loading Jenkins Dashboard
Run Jenkins in Docker – Unlock

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
6b7e5847bf7e41a5a90d8eceeade3e1b

Login to Jenkins web interface by using this password.

Jenkins Dashboard

Final Thoughts

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.

Exit mobile version