0% found this document useful (0 votes)
131 views11 pages

Springboot Docker MysqlRDS

This document provides steps to deploy a Spring Boot application with a MySQL database to Docker and Amazon ECS. It describes installing prerequisites like Java, Maven and Docker on an EC2 instance, creating an RDS MySQL database, building a Docker image from the Spring Boot code and database configuration, pushing the image to an ECR repository, creating an ECS cluster and running the Docker container on the cluster with a load balancer.

Uploaded by

Rabbani Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
131 views11 pages

Springboot Docker MysqlRDS

This document provides steps to deploy a Spring Boot application with a MySQL database to Docker and Amazon ECS. It describes installing prerequisites like Java, Maven and Docker on an EC2 instance, creating an RDS MySQL database, building a Docker image from the Spring Boot code and database configuration, pushing the image to an ECR repository, creating an ECS cluster and running the Docker container on the cluster with a load balancer.

Uploaded by

Rabbani Shaikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Deploy Spring Boot + MYSQL RDS Application to Docker and ECS

Prerequisites:
1. Python2
2. Maven
3. Java-1.8.0-openjdk & Java-1.8.0-openjdk-devel
4. Awscli
5. Docker
6. git
Create EC2 Instance  Here I used RHEL Amazon Machine Image
Update yum command:
yum update -y
Install java,git and wget:
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel wget git-y
Install Python2:
yum install python2-pip -y
alternatives --config python
Install Awscli:
pip2 install awscli
aws configure

Install Docker on RHEL:


Dnf config-manager --add repo=https://download.docker.com/linux/centos/docker-ce.repo
dnf install docker-ce-3:18.09.1-3.el7
systemctl enable docker
systemctl start docker
Create Mysql RDS:
 Please check below code to create MYSQL RDS instance
 Note: Here we should mention dbname to connect
aws rds create-db-instance \
--db-name mysqldb \
--allocated-storage 20 \
--db-instance-class db.t2.micro \
--db-instance-identifier mysqltest \
--engine mysql \
--master-username master \
--master-user-password Naresh#240

Pull file from github:


git clone https://github.com/Naresh240/springboot_mysqldb_docker.git

Move into file “springboot_mysqldb_docker”


cd springboot_mysqldb_docker
Then create jar file by using below command
mvn clean install
Requirements to create Docker Image:
 Here we need to check application.properties file
[Path:src/main/resources/application.properties]

url=jdbc:mysql://<Endpoint of date base>:<port-number>/dbname


In below figure we can check Endpoint

Create docker image:


docker build -t springboot_mysqldb_docker .

Run Docker image using below command:


docker run --name springboot_mysqldb_docker -p 8080:8080 -d springboot_mysqldb_docker
To check output we need postman app:
Goto postman:
To call insertemployee api:
1. Fix to Post and give url as http://100.26.35.194:8080/insertemployee
2. Click on Body given data in Json format

To call employee api:


http://100.26.35.194:8080/employees
Creating Repository on ECR using below steps:

 Click on Get Started

 Give Repository name as “springboot_mysqldb_docker” and Click on Create repository


 Below figure shows created Repository
Steps to push docker image to ECR:
1. Login to aws ECR:
$(aws ecr get-login --no-include-email --region us-east-1)

2. Build Docker images:


docker build -t springboot_mysqldb_docker .

3. Tag Docker image:


docker tag springboot_mysqldb_docker:latest 681475004840.dkr.ecr.us-east-
1.amazonaws.com/springboot_mysqldb_docker:latest
4. Push Docker image to ECR:
docker push 681475004840.dkr.ecr.us-east-1.amazonaws.com/dockernodejs:latest

Finally Repository stored in ECR:


Open ECS on AWS and Create Cluster using below steps and fill details:

 Click on Get started

 Click on Configure

 Click on update
 Click on Edit to give Run Task defination details

 Click on save and click Next and Edit details for Container Service
 Click on save and click on Next
 Click on Next
 Click on Create

Check below figure shows Cluster succefully created

After Creation of Cluster need to wait untill task status shows in RUNNING mode
Check Load Balancer, you will get new ELB

Copy DNS Name and give at GUI with port number and api
http://EC2Co-EcsEl-4VZ3CBBHY3M0-1984737267.us-east-1.elb.amazonaws.com:8080/insertemployee

To call insertemployee api:


1. Fix to Post and give url as above
2. Click on Body given data in Json format

To call employee api:


http://ec2co-ecsel-4vz3cbbhy3m0-1984737267.us-east-1.elb.amazonaws.com:8080/employees

You might also like