Simple Setup: Deploying a Jenkins Server with Docker on AWS EC2

paramita pal
4 min readAug 28, 2023

--

Are you struggling with Docker or Jenkins setup on AWS?
Don’t worry — this blog can be at your rescue to make you a well-versed in the process. In this, I’ll walk you through the following steps with ease:

1. Launching an EC2 instance on your AWS account.
2. Installing Docker on the EC2 instance.
3. Setting up Jenkins within a Docker container.
4. Alternate approach: one-click setup with AWS CloudFormation

Seems like a lot? Don’t worry, its really simple!

Step 1: Launching AWS EC2 Instance

Log in to your AWS account and follow these simple steps to launch an EC2 instance. If you’re having trouble locating the services, a quick search for “EC2” in the services search bar will do the trick. Once you’re on the “Launch Instances” page, you can enter the necessary details. In case you haven’t generated a key pair before, don’t hesitate to click on “Create new key pair” — I’ve included a helpful screenshot for reference.

After completing the steps above, click “Launch Instance” and pat yourself on the back — you’ve successfully tackled the first step.

Note: You need to add rule for the port 8080, by default it is not created. Follow the steps below:

  1. EC2-> Instances -> Select the correct instance(in this case “Web Server For Jenkins”
  2. Click on Security -> Select the security group -> Edit inbound rules
  3. Click on “Add rule” -> follow the screenshot
  4. Click on “Save rules”

Step 2: Installing Docker via AWS CLI

Now, let’s move on to the second part: installing Docker on your EC2 instance through the AWS Command Line Interface (CLI). Trust me, this won’t take long. I’ve provided the necessary scripts in a Git repository for your convenience. Simply copy the commands from the repository and follow along. But before you execute any commands, ensure that your current command prompt or Git Bash directory is where you’ve downloaded the “key_pair.pem” file.

To access the AWS CLI, run the following command (make sure to modify it according to your AWS account and EC2 instance details):

To find the command in your AWS account, go to your EC2 instance, click “connect” and click on “SSH Client” and copy the command(screenshot attached.)

Once you’re in the AWS CLI, you can effortlessly install Docker and Docker Compose to prepare for Jenkins installation. Check out the commands in my GitHub repository.(https://github.com/paramitapal/JenkinSetupInAWSEC2).

Step 3: Setting Up Jenkins in a Docker Container

The next phase is to launch your Jenkins server. Open your preferred browser and access the Jenkins server using the following format: https://[Public IPv4 address of EC2]:[port]

For instance, mine is http://44.203.202.185:8080/. As you access the server, you’ll be prompted with an “Unlock Jenkins” screen. Provide the “initialAdminPassword” that you saved earlier (you can find it at /var/lib/jenkins/secrets/initialAdminPassword).

After successfully logging in, initiate the installation of the recommended plugins by clicking “Install suggested plugins.” Feel free to let the installation process run its course; this might take a moment.

Final Touches: Set Your Username and Password You login and that’s it. Your Jenkins is ready to use, set your CI/CD environment for your project.

Step 4: [Alternate approach] one-click setup with AWS CloudFormation

This is for people like me, who hate following the step by step process in the console and need a one click solution to setup Jenkins setup in their account.
Just click the button and this CloudFormation template will take care of the setup magically for you. All you need to is select a pre-existing key-pair in your account as below:

After the CloudFormation is deployed, it’ll setup jenkins server for you. All you need to do after that is to go to the output section of your cloud formation stack and copy the JenkinsURL to open in your browser and the SSH command(JenkinsInitialPassword) to get jenkins initial admin password. And you are all set with the jenkin server. Note: It may take couple of mintues to showup in your browser.

If this blog helped you, please hit the like button and follow! :)

--

--

paramita pal

A tech enthusiast and software pro with [7+] years of Android expertise in SBI ALAPharma Inc. I also thrive in the cloud – AWS is my playground.