Running Jenkins in a Docker Container: A Beginner's Guide

Running Jenkins in a Docker Container: A Beginner's Guide

What is Jenkins?

Jenkins is a powerful and versatile open-source automation tool that is widely used for continuous integration and continuous delivery (CI/CD) of software projects. It enables developers to automate various aspects of software development, including building, testing, and deploying code changes. This makes it an essential tool for streamlining the software development process, improving efficiency, and reducing errors.

One of the main advantages of Jenkins is its ability to integrate with a wide range of tools and technologies, such as Git, Maven, and Docker. This allows developers to use Jenkins to automate their entire software development workflow, from code management to deployment.

Jenkins also provides an easy-to-use web interface for managing and monitoring the entire software development process. This includes features such as real-time build status, notifications, and reporting.

Jenkins Infrastructure

Master Server

  • Controls the Pipeline

  • Schedules Builds

Agents/Slaves

  • Perform the build

Prerequisites

  • Docker Desktop is running.

  • Basic Git and Github knowledge.

  • An Administrator Terminal

Installation

  1. Build the Jenkins BlueOcean Docker Image.

     docker build -t myjenkins-blueocean:2.332.3-1 .
    
  2. Create a network called "Jenkins".

     docker network create jenkins
    
  3. Test the network

     docker network ls
    

    You should be able to see a Jenkins bridge like the following

  4. Launch the Container.

    -- For Linux/macOS --

     docker run --name jenkins-blueocean --restart=on-failure --detach \
       --network jenkins --env DOCKER_HOST=tcp://docker:2376 \
       --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 \
       --publish 8080:8080 --publish 50000:50000 \
       --volume jenkins-data:/var/jenkins_home \
       --volume jenkins-docker-certs:/certs/client:ro \
       myjenkins-blueocean:2.332.3-1
    

    -- For Windows --

     docker run --name jenkins-blueocean --restart=on-failure --detach `
       --network jenkins --env DOCKER_HOST=tcp://docker:2376 `
       --env DOCKER_CERT_PATH=/certs/client --env DOCKER_TLS_VERIFY=1 `
       --volume jenkins-data:/var/jenkins_home `
       --volume jenkins-docker-certs:/certs/client:ro `
       --publish 8080:8080 --publish 50000:50000 myjenkins-blueocean:2.332.3-1
    
  5. Get the port on which the Container is running

    Mine is running on :8080

  6. Open a browser and go to your local host

    http://127.0.0.1:8080/

    http://localhost:8080/

  7. Get the Password from your terminal

    docker exec jenkins-blueocean cat /var/jenkins_home/secrets/initialAdminPassword

Copy whatever was in the output and paste it into your browser.

  1. Click on Install with Suggested Plugins

  2. Create your User Profile

    Congratulations your Jenkins is Ready to use, you can now build pipelines for your automation.

    Your Jenkins should look like this

Final Words

In conclusion, Jenkins is a powerful and versatile open-source automation tool that is widely used for continuous integration and continuous delivery (CI/CD) of software projects. By using Docker to containerize Jenkins, developers can easily run and manage their Jenkins environment, making it more efficient and easier to deploy.

Support me ~ Like and Comment on this blog post and Share it with your friends and Colleagues.

Special Thanks to DevOps Journey on Youtube

Did you find this article valuable?

Support Varchasv Hoon by becoming a sponsor. Any amount is appreciated!