Skip to main content

Command Palette

Search for a command to run...

Setting Up Docker Containers as Jenkins Build Agents

Updated
2 min read
Setting Up Docker Containers as Jenkins Build Agents
P

👋 Hi, I’m Praduman Prajapati — a DevOps Engineer with hands-on experience in building production-grade CI/CD pipelines, containerized applications, and scalable, secure, and automated cloud infrastructure.

I’ve work on multiple real-world projects including: • Automated CI/CD pipelines using Jenkins, GitHub Actions, and ArgoCD • Kubernetes cluster provisioning and deployment on AWS (EKS and kubeadm) • Containerization and orchestration with Docker and Kubernetes • Infrastructure provisioning and automation using Terraform and Ansible • DevSecOps implementations with Trivy, SonarQube, OWASP, Prometheus, and Grafana • Production-grade deployments of applications on cloud infrastructure

When the above steps done, then wait for the Jenkins to be started


Docker Slave Configuration

  • To install Docker, run the command below on the EC2 instance terminal

      sudo apt update && upgrade
      sudo apt install docker.io
    

  • Grant Jenkins user and ubuntu user permission to docker daemon and restart docker

      sudo su-
      usermod -aG docker jenkins
      usermod -aG docker ubuntu
      systemctl restart docker
    

  • Switch to the Jenkins user

      su jenkins
    
  • Check if the Jenkins user can run containers

      docker run hello-world
    

Sometimes jenkins might not pickup these changes. So, just restart your jenkins

  • To restart Jenkins, simply go to your browser and type

      http://<your-EC2-public-ip>:8080/restart
    

Install the Docker pipeline plugin in jenkins

We should install the Docker pipeline plugin so that Jenkins can work with Docker as an agent. This means that when running a job, Jenkins needs to know that if a user provides a Jenkins file to run a specific job on Docker, the configuration is in place

  • Click on Manage Jenkins

  • Click on plugins and install Docker pipeline plugin

  • Restart Jenkins after the installation is finished

Congratulations! You are now ready to begin creating your pipelines.

More from this blog

P

Praduman's blog

22 posts

Hi, I'm learning DevOps tools and concepts. I enjoy sharing my learning experiences and projects through blogs to help others who are on a similar journey.