Open In App

How to Setup Jenkins in Docker Container?

Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will look into the process of setting up Jenkins in a Docker container on an EC2 instance.

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

Now, let’s look step-by-step process for this setup.

Implementation:

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.

Make sure your Security inbound rules look like this. So that you don’t have any further issues.

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.

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

Step 3:  Now we will pull the Jenkins image using docker from the docker hub. 

Run the below command :

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.

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 

Now, copy the Public IPv4 address of the EC2 instance. Refer to the below image for any confusion.

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.

After running this, you’ll see a screen like this.

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

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.

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.


Last Updated : 30 Mar, 2023
Like Article
Save Article
Share your thoughts in the comments
Similar Reads