This repository demonstrates a real-world DevOps CI/CD pipeline using Jenkins, Docker, and AWS ECR, deployed on a single EC2 instance.
It’s designed for learning purposes, showing how code from GitHub can automatically be built, pushed to ECR, and deployed as a container.
GitHub → Jenkins (EC2) → Docker → AWS ECR → EC2 (runs container)
- Jenkins: Installed on EC2, orchestrates the pipeline.
- Docker: Containerizes the application.
- AWS ECR: Stores Docker images for deployment.
- EC2: Hosts both Jenkins and the running container.
⚡ Simple, production-like setup for learning CI/CD without using EKS or Kubernetes.
- Ubuntu 22.04 EC2 instance
- Docker installed
- Jenkins installed
- AWS CLI configured with credentials
- AWS ECR repository
- OS: Ubuntu 22.04
- Instance type: t2.micro
- Storage: 20 GB
- Security Group: Open ports
- 22 (SSH)
- 8080 (Jenkins)
- 80 (App)
ssh -i your-key.pem ubuntu@<your-ec2-public-ip>sudo apt update -y
# Docker
sudo apt install docker.io -y
sudo systemctl start docker
sudo systemctl enable docker
sudo usermod -aG docker ubuntu
# Java for Jenkins
sudo apt install openjdk-17-jdk -y
# Jenkins
curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee /usr/share/keyrings/jenkins-keyring.asc > /dev/null
echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] https://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list > /dev/null
sudo apt update
sudo apt install jenkins -y
sudo systemctl start jenkins
# AWS CLI
sudo apt install unzip -y
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
# Permissions
sudo usermod -aG docker jenkins
sudo systemctl restart jenkins
# Verify
docker --version
aws --version- Open:
http://<EC2-IP>:8080 - Get initial password:
sudo cat /var/lib/jenkins/secrets/initialAdminPassword- Install suggested plugins
- Create admin user
aws configureEnter:
- Access Key ID
- Secret Access Key
- Default region (e.g.,
us-east-1)
aws ecr create-repository --repository-name devops-appCopy repository URL:
<account-id>.dkr.ecr.<region>.amazonaws.com/devops-app
Include:
JenkinsfileDockerfile- Application code (
app.js,package.json)
- Jenkins → New Item → Pipeline → Name:
devops-cicd - Pipeline script from SCM → Git → URL: your repo → Script Path:
Jenkinsfile
pipeline {
agent any
environment {
AWS_REGION = "us-east-1"
ECR_REPO = "<your-ecr-repo>"
IMAGE_NAME = "devops-app"
CONTAINER_NAME = "app"
}
stages {
stage('Clone') {
steps {
git '<your-github-repo-url>'
}
}
stage('Build Image') {
steps {
sh 'docker build -t $IMAGE_NAME .'
}
}
stage('ECR Login') {
steps {
sh '''
aws ecr get-login-password --region $AWS_REGION | \
docker login --username AWS --password-stdin $ECR_REPO
'''
}
}
stage('Tag Image') {
steps {
sh 'docker tag $IMAGE_NAME:latest $ECR_REPO:latest'
}
}
stage('Push Image') {
steps {
sh 'docker push $ECR_REPO:latest'
}
}
stage('Deploy') {
steps {
sh '''
docker stop $CONTAINER_NAME || true
docker rm $CONTAINER_NAME || true
docker run -d -p 80:3000 --name $CONTAINER_NAME $ECR_REPO:latest
'''
}
}
}
}- Click Build Now in Jenkins
- Pipeline will:
- Pull code from GitHub
- Build Docker image
- Push image to ECR
- Deploy container on EC2
Open in browser:
http://<EC2-IP>
You should see your application running.
- GitHub → Settings → Webhooks
- Payload URL:
http://<EC2-IP>:8080/github-webhook/ - Content type:
application/json - Events: Just the push event
- This project is for learning Jenkins and CI/CD pipelines.
- No complex orchestration like EKS/Kubernetes — simplicity for understanding pipeline flow.
- Can be recreated on any EC2 for practice.
- Jenkins pipeline creation & stages
- Docker image build and management
- AWS ECR integration
- Continuous deployment to EC2
- GitHub webhook triggers





