DEV Community

Cover image for How to Set Up Jenkins with Docker for CI/CD Pipelines: A Step-by-Step Guide
Md Sharjil Alam
Md Sharjil Alam

Posted on

How to Set Up Jenkins with Docker for CI/CD Pipelines: A Step-by-Step Guide

Hey Dev.to Family! πŸ‘‹
In this article, we'll explore the CI/CD process and how Jenkins can simplify the automation of building, testing, and deploying your applications. We'll also cover how Docker can be used as an agent in Jenkins to make your builds more reliable and easier to manage.

Table of Contents

  1. CI/CD: Continuous Integration and Continuous Delivery
  2. Standard Steps in CI/CD Pipeline
  3. Why Jenkins for CI/CD?
  4. Step-by-Step Jenkins Setup on AWS EC2
  5. Jenkins in Detail
  6. Conclusion

CI/CD: Continuous Integration and Continuous Delivery

CI/CD is a crucial process in software development that automates the integration of code changes (CI) and their delivery to production (CD). This automation helps in improving code quality, reducing errors, and accelerating deployment.

Standard Steps in CI/CD Pipeline

  1. Unit Testing: Verifies that individual components of the code work as intended.
  2. Static Code Analysis: Checks the code for potential bugs, adherence to coding standards, and style violations.
  3. Code Quality/Vulnerability Checks: Ensures the security and performance of the code by identifying vulnerabilities and quality issues.
  4. Automation: Automates the build, test, and deployment processes to streamline development workflows.
  5. Reports: Provides feedback on test results, code quality, and other relevant metrics.
  6. Deployment: Automates the delivery of code to production or staging environments.

Why Jenkins for CI/CD?

  • Open-Source: Jenkins is a free and widely-used tool that supports automating the entire build, test, and deployment pipeline.
  • Plugin Ecosystem: Offers a wide range of plugins to extend its capabilities and integrate with various tools.
  • Master-Worker Architecture: Supports a distributed system with a master node managing and worker nodes executing tasks.
  • Integration with Tools: Easily integrates with Docker, AWS, Git, and other tools to create a seamless CI/CD pipeline.

Jenkins Architecture

Step-by-Step Jenkins Setup on AWS EC2

  1. Set Up an EC2 Instance

    Launch an AWS EC2 instance (preferably Ubuntu) to host Jenkins.

  2. Security Group Configuration

    • Edit Inbound Rules: In the Security Group settings, add a rule for Custom TCP on port 8080 (Jenkins) and ensure SSH access via port 22.
  3. Access Jenkins

    • Use the public IP of your EC2 instance to access Jenkins via http://<public_ip>:8080.
    • Log in with the admin username and password provided during Jenkins setup.
  4. Jenkins Master and Worker Nodes

    • Master Node: The central server that manages Jenkins operations and job scheduling.
    • Worker Nodes: Servers that execute the build and test jobs distributed by the master node.
  5. Installing Docker as a Jenkins Agent

    • Why Docker?: Docker simplifies the creation of isolated, reproducible environments for each build, enhancing build reliability and management.
    • Installation:
     sudo apt install docker.io
    
  • Grant Jenkins Access to Docker:

     sudo usermod -aG docker jenkins
    
  • Install Docker Pipeline Plugin:

    • Navigate to Manage Jenkins β†’ Manage Plugins.
    • Search for and install the Docker Pipeline plugin.
  • Docker as an Agent:

Docker as an Agent

  1. Further Configuration
    • Adjust the sequence and configuration based on best practices and specific requirements of your environment.

Jenkins in Detail

  • Jenkins Master: The central controller that manages job scheduling and execution.
  • Jenkins Worker Nodes: Nodes that execute the build and test jobs as directed by the master.
  • Docker as Agent: Using Docker as an agent allows Jenkins to create isolated build environments. This approach improves the consistency and manageability of builds.

Conclusion

Getting hands-on with Jenkins and Docker has provided valuable insights into automating and managing your CI/CD pipelines. Jenkins excels at managing builds and integrating with a wide array of tools, while Docker makes the build environments reproducible and easier to manage. Together, these tools offer a comprehensive solution for CI/CD automation.

Let's Connect! πŸ”— For more updates and insights:

#DevOps #Jenkins #Docker #CI/CD #TechBlog

Happy learning! 😊

Top comments (0)