Open In App

How to Setup Jenkins in Docker Container?

Last Updated : 06 Jan, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

Setting up of Jenkins in a docker container provides the facility of streamlining the CI/CD with scalability and consistency. It also helps for attaching the worker nodes as slaves and run the build jobs over their. In this article, we will guide you through the process of deploying jenkins in a Docker container over AWS Cloud EC2 instance.

What is Jenkins?

Jenkins is an open-source automation server widely used for continuous integration (CI) and continuous delivery (CD) processes in software development. It allows developers to automate the building, testing, and deployment of code changes, ensuring rapid and reliable software delivery. With its vast plugin ecosystem and flexibility, Jenkins has become a cornerstone tool for modern software development teams, enabling efficient collaboration and faster time-to-market for applications.

Primary Terminologies

  • Jenkins is an open-source automation server that is used to automate different parts of your software development related to building, testing, and deploying.
  • Docker is a set of platforms as a service product that uses OS-level virtualization to deliver software in packages called containers.
  • EC2 or Elastic Compute Cloud is a scalable computing service launched on the AWS cloud platform.

How to Setup Jenkins in Docker Container? A Step-By-Step Guide

The following are the steps that guides in setting up the jenkins in docker container using AWS EC2 instances:

Step 1:  First, log in to your AWS account and go to the EC2 service. There launch any free tier Amazon Linux machine. Here is the image attached to refer to.

Choosing AMISetting Inbound rules

Step 2:  After launching, SSH to that EC2 instance. And Install Docker by running the following commands.

sudo yum update -y                             # To update all packages
sudo amazon-linux-extras install docker # To install docker latest version
sudo service docker start # To start docker service
sudo service docker status # To check status of docker service. If it's running or not.
sudo systemctl enable docker # To ensure that docker service start after each reboot
sudo usermod -a -G docker ec2-user # To add ec2-user to docker group
  • Refer to the below images for the output of the above commands.
Updating the softwares
  • The following screenshot illustrates on installation of docker on AWS Amazon Linux:
Installation of Docker
  • The following screenshot illustrates on the checking and starting the docker service:
Start docker service
  • Now, to check if docker is installed or not. Run below command and match with an image attached further.
docker  -v               # It will give you docker version
docker version

Step 3:  Now we will pull the Jenkins image using docker from the docker hub. Run the following command to pull the docker images such jenkins/jenkins.

docker pull jenkins/jenkins        # To pull the image of jenkins
docker images # To see if image is downloaded or not
  • Please refer to the image attached for a better understanding.
pulling jenkins image

Step 4:  Since in docker images we can see our Jenkins image. Now we can make our Jenkins container. But before that make a directory. Run below command 

mkdir jenkins          #To make directory name jenkins 
  • After making this directory run the below command Please refer to the image attached ahead for a better understanding.
docker run -d --name jenkins -p 8080:8080 -v $PWD/jenkins/ jenkins/jenkins      # To run a container name jenkins using jenkins image 
docker ps # To see if container is running or not
Creating docker container with jenkins
  • Now, copy the Public IPv4 address of the EC2 instance. Refer to the below image for any confusion.
Copying the Public IP
  • After copying it. Paste it into a new tab and write it with port 8080. Refer the below image for better understanding and resolving confusion.
Accessing the jenkins server
  • After running this, you'll see a screen like this.
providing the password to jenkins console

Step 5: To get this password. Run the below command in the EC2 instance and copy the password. Refer to the image if there is any confusion.

docker logs jenkins                          #To see logs of the container name jenkins
imageedit24559842422-copy-2


  • After entering this password, Install all the plugins (it may take a while). 

Step 6:  Once all the plugins are installed you'll be asked to make a user with a password and After making that user. You'll be logged into Jenkins.

Installing suggested plugins
  • The following screenshot illustrates on creation of new admin user:
  • Access to the jenkins web dashobard as shown in the below screenshot.
  • Congratulations! If you have come this far that's mean you have successfully set up the Jenkins in Docker container. Now you can easily automate your software using Jenkins.

Difference between Jenkins and Docker

The following are the difference between Jenkins and docker:

AspectJenkinsDocker
PurposeJenkins is a tool that used for Continuous Integration and Continuous Delivery (CI/CD) for automating software development processesIt is a containerization platform that is used for building, deploying, and managing applications within containers
FunctionalityIt manages and automates tasks such as building, testing, and deploying code across different stages of the development pipelineit creates lightweight, portable containers that encapsulate applications with all their dependencies providing consistent and reproducible environments
ArchitectureIt follows master-slave architecture where jenkins master coordinates tasks and distributes work to multiple slave nodesIt comes with Client-server architecture, where Docker Engine acts as the server managing containers, and Docker CLI interacts with the server to execute commands
Use CasesIt is ideal for automating software development workflows. It integrates with version control systems, and orchestrating complex build and deployment pipelinesIt is suitable for containerizing applications, microservices, and distributed systems, providing flexibility, scalability, and portability across different environments

Why Jenkins use Docker?

The following are the reasons for jenkins using docker:

  • Scalability: Docker facilitates the jenkins with dynamically provision features for build agents as Docker containers allowsing for efficient scaling of resources based on workload demands.
  • Isolation: Docker provides light weighted isolated containers for running build jobs, ensuring each build runs in its isolated enviornments.
  • Consistency: By using docker continers, jenkins ensures the consistency between development, testing and production environments.
  • Resource Efficiency: Docker containers consumes fewer resources compared to the traditional vritual machines making them a more efficient choice for running build jobs.

Next Article
Article Tags :

Similar Reads